使用此脚本,先先在磁盘建好相应的路径.根据自己的需要更改备份路径.
1 declare @Now datetime,@TodayString varchar(30),@FileName varchar(100),@DataBaseName varchar(100)
2
3 set @DataBaseName = 'CbData' --数据库名称
4
5
6 set @Now = GETDATE()
7 select @TodayString = CONVERT(varchar(30),@Now,120)
8 select @TodayString = replace(replace(replace(@TodayString,'-',''),':',''),' ','')
9
10
11 if DATEPART(hh,@Now)<=12 --上午备份路径 可以根据自己的需要进行修改
12 set @FileName = 'F:\'+@DataBaseName+'Backup_Noon\'+@DataBaseName+'_'+@TodayString+'.trn'
13 else --下午备份路径
14 set @FileName = 'F:\'+@DataBaseName+'Backup_Night\'+@DataBaseName+'_'+@TodayString+'.trn'
15
16
17
18 backup Database @DataBaseName
19 To DISk =@FileName