Danh hiệu: Kê Vương
Gia nhập: 23-01-2011(UTC) Bài viết: 2,113 Đến từ: HCM Thanks: 4 times Được cảm ơn: 300 lần trong 220 bài viết
|
Mã:set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO ALTER proc [dbo].[sp_upd_Backup_All_Database_Daily] @Path nvarchar(255) AS BEGIN declare @count int
update tbl_Backup_Daily set Backup_Count = Backup_Count + 1 set @count = (select top 1 Backup_Count % 2 from tbl_Backup_Daily)
declare @dbName varchar(500) declare cur cursor
for SELECT name FROM sysdatabases where not (name in ('master', 'model', 'msdb', 'tempdb')) open cur
fetch next from cur into @dbName while @@fetch_status = 0 begin declare @Temp_Path nvarchar(300) set @Temp_Path = @Path + '\' + @dbName + '_' + convert(varchar, @count)
if (not (@dbname like '%AdventureWorks%')) BEGIN exec('backup log ' + @dbName + ' with no_log') exec ('dbcc shrinkdatabase( ' + @dbName + ')') exec('backup database ' + @dbName + ' to disk=''' + @Temp_Path +'.bak'' with format')
declare @FulDateFile nvarchar(200) set @FulDateFile = Replace(convert(nvarchar, getdate(), 105), '-', '') set @FulDateFile = @FulDateFile + @dbName + '_' + convert(varchar, @count)
declare @Command nvarchar(2000) set @Command = 'C:\TKS\AZCopy\azcopy copy "C:\TKS\DatabaseBK\' +@dbName + + '_' + convert(varchar, @count) + '.bak" "https://<tên blob>.blob.core.windows.net/<container>/' +@FulDateFile+'.bak?SAS"' print @Command exec xp_cmdshell @Command END fetch next from cur into @dbName end
close cur deallocate cur END
|