情景: 有几台老的sqlserver数据库,由于本地空间不足,又无法扩容,导致备份经常失败。
故考虑使用远程备份方式,添加网络路径完成备份操作。
1. 启用xp_cmdshell
--mster下执行
如果没有启用xp_cmdshell,请执行以下启用:
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
EXEC sp_configure 'xp_cmdshell', 1;
RECONFIGURE;
2、在sqlserver中执行net use 命令,添加网络地址
--共享目录有权限
exec master..xp_cmdshell 'net use Z: \\10.100.192.83\share'
--只有指定用户的权限
exec master..xp_cmdshell 'net use Z: \\10.100.192.83\share password /user:admin'
--删除目录命令
exec master..xp_cmdshell 'net use Z: /delete' ----删除映射盘
3、添加好网络路径Z:之后可以在备份设置中看到对应的目录。剩下的按照正常备份就OK了。
注意:
从服务器访问网络地址的速度要保证,会影响备份效率。