答:在數據庫任務中以以下腳本可實現數據庫的定時備份:
-- 異地備份
-- 第一步:使用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