SQL异地备份
首先准备工作:开启SQL server Agent 服务,外围配置开启 xp_cmdshell,设置远程备份目标文件夹共享
--获取操作权限
Exec master..xp_cmdshell 'net use \\ipaddress\backupFolder password /User:ip\Administrator'/*
PS:调用xp_cmdshell需要在SQL外围配置器中设置允许xp_cmdshell
net use \\192.168.1.108\easyworktools\test 远程IP+备份文件夹
admin@cti 登录密码
/User:192.168.1.108\Administrator 登录用户
*/
--备份名称,年-月-日.bak
DECLARE @bakName VARCHAR(200)
SET @bakName='\\ipaddress\folder\'+CONVERT(VARCHAR,YEAR(GETDATE()))+'-'+CONVERT(VARCHAR,MONTH(GETDATE()))+'-'+CONVERT(VARCHAR,DAY(GETDATE()))+'.bak'
Backup Database [test] to Disk = @bakName
--删除映射
exec master..xp_cmdshell 'net use \\ipaddress\folder\ /delete'