数据库定时备份
作者:网络转载 发布时间:[ 2015/12/31 10:35:49 ] 推荐标签:数据库 数据库备份
--新建文件夹
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'xp_cmdShell', 1;
GO
RECONFIGURE
GO
declare @currentDate datetime,@Day varchar(20)
set @currentDate=getdate()
set @Day= cast(year(@currentDate) as varchar(4))+'_'+cast(month(@currentDate) as varchar(2))+'_'+cast(day(@currentDate) as varchar(2))
declare @cmd varchar(1000)
--set @cmd=N'mkdir D:Program FilesMicrosoft SQL Server实例根MSSQL11.SQL0MSSQLBackupAdventureWorks2012_'+@Day
set @cmd=N'mkdir D:Program FilesAdventureWorks2012_'+@Day
--set @cmd=N'mkdir D:dbAdventureWorks2012_'+@Day
select @cmd
exec xp_cmdshell @cmd
--完备
go
declare @strDate varchar(30),@backupFile varchar(200),@backupLogFile varchar(200),@currentDate datetime,@Day varchar(20)
set @currentDate=getdate()
set @Day= cast(year(@currentDate) as varchar(4))+'_'+cast(month(@currentDate) as varchar(2))+'_'+cast(day(@currentDate) as varchar(2))
set @strDate=@Day+'_'+cast(datepart(hour,@currentDate) as varchar(2))+'_'+cast(datepart(minute,@currentDate) as varchar(2))+'_'+cast(datepart(ss,@currentDate) as varchar(2))
set @backupFile = 'D:dbAdventureWorks2012_'+@Day+'AdventureWorks2012_'+@strDate+'.bak'
backup database AdventureWorks2012 to disk=@backupFile WITH NOFORMAT, NOINIT,
NAME = N'AdventureWorks2012-完整 数据库 备份',
SKIP, NOREWIND, NOUNLOAD
--log备份
go
declare @strDate varchar(30),@backupFile varchar(200),@backupLogFile varchar(200),@currentDate datetime,@Day varchar(20)
set @currentDate=getdate()
set @Day= cast(year(@currentDate) as varchar(4))+'_'+cast(month(@currentDate) as varchar(2))+'_'+cast(day(@currentDate) as varchar(2))
set @strDate=@Day+'_'+cast(datepart(hour,@currentDate) as varchar(2))+'_'+cast(datepart(minute,@currentDate) as varchar(2))+'_'+cast(datepart(ss,@currentDate) as varchar(2))
set @backupLogFile='D:dbAdventureWorks2012_'+@Day+'AdventureWorks2012_'+@strDate+'.trn'
backup log AdventureWorks2012 to disk=@backupLogFile
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11