答:在數(shù)據(jù)庫任務(wù)中以以下腳本可實(shí)現(xiàn)數(shù)據(jù)庫的定時(shí)備份:
-- 異地備份
-- 第一步:使用net命令連接異地服務(wù)器
-- 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
-- 第二步:執(zhí)行備份
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