第一步: 开启cmdshel
EXEC sp_configure 'show advanced options', 1
RECONFIGURE
EXEC sp_configure 'xp_cmdshell', 1
RECONFIGURE
第二步:创建网络映射
exec master..xp_cmdshell 'net use \\192.168.10.x\DBBackTest password /user:UserName
说明:
远程共享路径:\\192.168.10.x\DBBackTest
Password :密码
UserName:用户名
第三步:备份数据到远程服务指定的共享路径
declare @ss varchar(50)
set @ss = convert(varchar(100),GetDate(),112)
set @ss = '\\192.168.10.x\DBBackTest\'+@ss+'.bak'
backup database testDB to disk = @ss WITH FORMAT
第四步:删除网络映射
exec master..xp_cmdshell 'net use \\192.168.10.x\DBBackTest /delete'