备份到远程服务器

来源:互联网 发布:学手语的软件 编辑:程序博客网 时间:2024/05/24 04:42
--如果xp_cmdshell没有启用,请先启用sp_configure 'show advanced options',1reconfiguregosp_configure 'xp_cmdshell',1reconfigureGO--1.先创建映射--要备份的共享路径:\\192.168.50.13\share--账户密码:实际的远程密码--账户:192.168.50.13\administratorexec master..xp_cmdshell 'net use \\192.168.50.13\share password /user:192.168.50.13\administrator'--2.利用映射备份数据库backup DATABASE test to disk=N'\\192.168.50.13\share\test.bak' WITH COMPRESSION--3.删除映射exec master..xp_cmdshell 'net use \\192.168.50.13\share /delete'


但 xp_cmdshell 开启毕竟不安全, 因此在备份完成之后应该关闭才对, 上面的代码测试成功之后,SQL作业的脚本里可以这样写:

--如果xp_cmdshell没有启用,请先启用sp_configure 'show advanced options',1reconfiguregosp_configure 'xp_cmdshell',1reconfigureGO--备份数据库backup DATABASE test to disk=N'\\192.168.50.13\share\test.bak' WITH COMPRESSIONgosp_configure 'xp_cmdshell',0reconfigureGO


0 0
原创粉丝点击