You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
918 B
36 lines
918 B
1 year ago
|
|
||
|
|
||
|
DECLARE @Dir VARCHAR(200)
|
||
|
SELECT @Dir = 'F:\AppData_Bak\'
|
||
|
DECLARE @Name VARCHAR(100)
|
||
|
DECLARE List CURSOR FOR
|
||
|
SELECT name FROM master..sysdatabases
|
||
|
WHERE STATUS & 512 != 512
|
||
|
OPEN LIST
|
||
|
FETCH List INTO @Name
|
||
|
WHILE @@FETCH_STATUS = 0
|
||
|
BEGIN
|
||
|
PRINT 'EXECUTE master.dbo.xp_create_subdir N'''+@dir+''+ @name + ''''
|
||
|
print ''
|
||
|
|
||
|
DECLARE @FileName VARCHAR(500)
|
||
|
DECLARE @BackName VARCHAR(50)
|
||
|
SELECT @BackName = @Name + '_backup_'+ REPLACE(REPLACE(REPLACE( CONVERT(VARCHAR,GETDATE(),120),'-',''),':',''),' ','')
|
||
|
SELECT @FileName = @Dir + @Name + '\' + @BackName+ '.bak'
|
||
|
|
||
|
DECLARE @backupSql VARCHAR(1000)
|
||
|
|
||
|
SELECT @backupSql = 'BACKUP DATABASE ['+@name+'] TO DISK = N'''+@fileName+''' WITH NOFORMAT, NOINIT, NAME = N'''+@BackName+''', SKIP, REWIND, NOUNLOAD, STATS = 10'
|
||
|
print @backupSql
|
||
|
print ''
|
||
|
print ''
|
||
|
|
||
|
FETCH List INTO @Name
|
||
|
END
|
||
|
|
||
|
CLOSE LIST
|
||
|
DEALLOCATE LIST
|
||
|
|
||
|
|
||
|
|
||
|
|