首先将异地备份的硬盘空间(e盘)进行共享,在数据库源添加网络映射,将异地备份盘添加到本地 例如:z盘
配置作业,脚本如下:
EXEC sp_configure 'xp_cmdshell', 1
GO
RECONFIGURE
GO
--DECLARE @databasename NVARCHAR(20)
--set @databasename = 'SSO'
--DECLARE @strPath NVARCHAR(200)
--set @strPath = convert(NVARCHAR(19),getdate(),120)
--set @strPath = REPLACE(@strPath, ':' , '.')
--set @strPath = 'z:\sqlbackup\' + @databasename+@strPath + '.bak'
exec master..xp_cmdshell N'net use z: \\异地存放数据端目标端IP\e$ "密码" /user:目标端IP\用户名'
backup database [sso] to disk='z:\sqlbackup\sso.bak'
--with retaindays=1
--BACKUP DATABASE @databasename TO DISK = @strPath with retaindays=1
EXEC sp_configure 'xp_cmdshell', 0
GO
RECONFIGURE WITH OVERRIDE
GO