当前位置: 代码迷 >> Sql Server >> 请教SQL2005自动备份如何改备份文件名
  详细解决方案

请教SQL2005自动备份如何改备份文件名

热度:59   发布时间:2016-04-27 16:11:13.0
请问SQL2005自动备份怎么改备份文件名?
在维护计划里面添加subplan之后,增加“备份数据库”任务,只能指定备份文件存放的文件夹,怎么更改备份文件名?
不管全备还是差异出来的文件名都是
TestDB_backup_200708211900.bak   这样的,怎么更改呢?谢谢!

------解决方案--------------------
这里的w:\为路径
这是偶几天写的,针对几十个数据库自动备份、删除4天前的备份(由于周六日休息,所以用del1,2,3,4删除以4天前5天前6前的备份)
用以下SQL调度
declare @s nvarchar(4000),@s2 nvarchar(4000),@del nvarchar(4000),@del2 nvarchar(4000),
@del3 nvarchar(4000),@del4 nvarchar(4000),@del5 nvarchar(4000),@del6 nvarchar(4000)
select @s= ' ',@s2= ' ',@del= ' ',@del2= ' ',@del3= ' ',@del4= ' ',@del5= ' ',@del6= ' '
select
@s= @s+
case when dbid !> 31 then char(13)+ 'backup database '+quotename(Name)+ ' to disk = ' 'w:\ '+Name+ '_ '+convert(varchar(8),getdate(),112)+ '.bak ' ' with init ' else ' ' end,
@[email protected]+
case when dbid > 31 then char(13)+ 'backup database '+quotename(Name)+ ' to disk = ' 'w:\ '+Name+ '_ '+convert(varchar(8),getdate(),112)+ '.bak ' ' with init ' else ' ' end,
@[email protected]+
case when dbid !> 31 then char(13)+ 'exec master..xp_cmdshell ' ' del w:\ '+Name+ '_ '+convert(varchar(8),getdate()-4,112)+ '.bak ' ', no_output ' else ' ' end,
@[email protected]+
case when dbid > 31 then char(13)+ 'exec master..xp_cmdshell ' ' del w:\ '+Name+ '_ '+convert(varchar(8),getdate()-4,112)+ '.bak ' ', no_output ' else ' ' end,
@[email protected]+
case when dbid !> 31 then char(13)+ 'exec master..xp_cmdshell ' ' del w:\ '+Name+ '_ '+convert(varchar(8),getdate()-5,112)+ '.bak ' ', no_output ' else ' ' end,
@[email protected]+
case when dbid > 31 then char(13)+ 'exec master..xp_cmdshell ' ' del w:\ '+Name+ '_ '+convert(varchar(8),getdate()-5,112)+ '.bak ' ', no_output ' else ' ' end,
@[email protected]+
case when dbid !> 31 then char(13)+ 'exec master..xp_cmdshell ' ' del w:\ '+Name+ '_ '+convert(varchar(8),getdate()-6,112)+ '.bak ' ', no_output ' else ' ' end,
@[email protected]+
case when dbid > 31 then char(13)+ 'exec master..xp_cmdshell ' ' del w:\ '+Name+ '_ '+convert(varchar(8),getdate()-6,112)+ '.bak ' ', no_output ' else ' ' end

from master..sysdatabases where dbid> 4 order by dbid asc

exec (@[email protected][email protected][email protected][email protected][email protected])

exec(@[email protected])
  相关解决方案