日期:2014-05-17 浏览次数:20574 次
EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO
EXEC sp_configure 'xp_cmdshell', 1
GO
RECONFIGURE
GO
exec master..xp_cmdshell 'net use z: \\HITBJWEB1\databaseback "密码" /user:HITBJWEB1\administrator'
/*--说明:
z: 是映射网络路径对应本机的盘符,与下面的备份对应
\\HITBJWEB1\databaseback 是要映射的网络路径
HITBJWEB1\administrator HITBJWEB1是远程的计算机名或所在域名,administrator是登陆的用户名
密码 上面指定的administrator用户的密码
--*/
--进行数据库备份
declare @str nvarchar(100)/*备份路径*/
declare @fileNme nvarchar(100)/*文件名*/
declare @curDay datetime/*当前时间*/
declare @curWeek int/*当前时间所在当前月的第几周*/
set @curDay=GETDATE()
set @curWeek=DATEPART(WEEK,@curDay)-DATEPART(WEEK,DATEADD(dd,-day(@curDay),@curDay))+1
set @fileNme=cast(@curWeek as nvarchar(10))+'.bak'
set @str = 'z:\db\'+@fileNme
backup database db to disk=@str WITH CHECKSUM,init
set @str = 'z:\db1\'+@fileNme
backup database db1 to disk=@str WITH CHECKSUM,init
--备份完成后删除映射
exec master..xp_cmdshell 'net use z: /delete'
EXEC sp_configure 'xp_cmdshell', 0
GO
RECONFIGURE
GO
EXEC sp_configure 'show advanced options', 0
GO
RECONFIGURE
GO