Sqlserver DataBase BackUp Order (Ex:WF) Sqlserver 数据库备份命令

CREATE PROCEDURE dbo.Sp_DataBase_Backup_Day AS
  declare
    @FilePath nvarchar(255),
    @CommandString nvarchar(255),
    @dbname nvarchar(255),
    @Gs int

set @Gs=1
WHILE (@Gs < 7)
BEGIN
   IF (@Gs = 1) set @dbname='derwent'
   IF (@Gs = 2) set @dbname='imis2009'
   IF (@Gs = 3) set @dbname='investext'
   IF (@Gs = 4) set @dbname='master'
   IF (@Gs = 5) set @dbname='wengfu'
   IF (@Gs = 6) set @dbname='wfsmsdb'
 
--备份
  set @FilePath = 'D:\WF_ServerDB_Back\'+@dbname+'(' + convert(char(8), getdate(), 112) + ').bak'
  print @FilePath BACKUP DATABASE @dbname TO DISK = @FilePath WITH INIT, NAME = N'DB_日数据备份', NOSKIP, NOFORMAT

--压缩
  set @CommandString = '"C:\Program Files\WinRAR\WinRAR" A -ibck -ep ' + replace(@FilePath, '.bak', '.rar') + ' ' + @FilePath
  print @CommandString
  exec xp_cmdshell @CommandString

--删除
  set @CommandString ='del ' + @FilePath
  print @CommandString
  exec xp_cmdshell @CommandString
  set @Gs=@Gs+1
END
GO

你可能感兴趣的:(sqlserver)