-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Создание бекапов нескольких БД с фильтром по имени
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/***************************************** | ||
Создание бекапов нескольких БД с фильтром по имени | ||
*******************************************/ | ||
|
||
DECLARE @name VARCHAR(50) -- database name | ||
DECLARE @path VARCHAR(256) -- path for backup files | ||
DECLARE @fileName VARCHAR(256) -- filename for backup | ||
DECLARE @fileDate VARCHAR(20) -- used for file name | ||
DECLARE @likeFilter VARCHAR(256) -- used for LIKE to filter db names | ||
|
||
-- specify database backup directory | ||
SET @path = '/some/path/to/backup' | ||
|
||
-- specify filename format | ||
SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) | ||
|
||
DECLARE db_cursor CURSOR READ_ONLY FOR | ||
SELECT name | ||
FROM master.dbo.sysdatabases | ||
WHERE name LIKE @likeFilter | ||
|
||
OPEN db_cursor | ||
FETCH NEXT FROM db_cursor INTO @name | ||
|
||
WHILE @@FETCH_STATUS = 0 | ||
BEGIN | ||
SET @fileName = @path + @name + '_' + @fileDate + '.BAK' | ||
BACKUP DATABASE @name TO DISK = @fileName | ||
|
||
FETCH NEXT FROM db_cursor INTO @name | ||
END | ||
|
||
CLOSE db_cursor | ||
DEALLOCATE db_cursor |