答:在数据库任务中以以下脚本可实现数据库的定时备份:
-- 异地备份
-- 第一步:使用net命令连接异地服务器
-- To allow advanced options to be changed.
EXEC sp_configure 'show advanced options', 1
GO
-- To update the currently configured value for advanced options.
RECONFIGURE
GO
-- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1
GO
-- To update the currently configured value for this feature.
RECONFIGURE
GO
EXEC xp_cmdshell 'net use \\192.168.1.6\d$\shq_bak password /user:administrator',no_output
-- 第二步:执行备份
declare @day int
set @day = datepart(weekday,getdate())
if (@day in (3,5,7)) begin
backup database enjoy_shq to disk='\\192.168.1.6\d$\shq_bak\enjoy_shq01.bak' with init
end else if (@day in (2,4,6)) begin
backup database enjoy_shq to disk='\\192.168.1.6\d$\shq_bak\enjoy_shq02.bak' with init
end else begin
backup database enjoy_shq to disk='\\192.168.1.6\d$\shq_bak\enjoy_shq01.bak' with init
end