SQL实现远程备份本保存备份文件到本地

来源:互联网 发布:c语言 udp多线程编程 编辑:程序博客网 时间:2024/05/31 19:56

  --SQL如何备份到异机

  --写成存储过程,建立作业定时备份~~~

  sp_configure 'show advanced options',1

  reconfigure

  go

  sp_configure 'xp_cmdshell',1

  reconfigure

  go

  --在sql中映射一下就可以了

  exec master..xp_cmdshell 'net use z: \\192.168.1.18\D$ "123456" /user:192.168.1.18\User1'

  /*--说明:

  exec master..xp_cmdshell 'net use z: \\本地IP地址或机器名\c$ "密码" /user:本地IP地址或机器名\用户名'

  z:是映射网络路径对应本机的盘符,与下面的备份对应

  \\xz\c$是要映射的网络路径

  xz\administrator

  xz是远程的计算机名,

  administrator是登陆的用户名

  密码 面指定的administrator用户的密码

  --*/

  --备份;with init覆盖 |noinit添加

  backup database KF_Exam_1 to disk='Z:\H_BACKUP.bak' with init

  --COPY

  --exec master..xp_cmdshell 'copy E:\H_BACKUP.bak z:'

  --删除(这句可以去掉)

  --exec master..xp_cmdshell 'del E:\H_BACKUP.bak'

  --完成后删除映射

  exec master..xp_cmdshell 'net use z: /delete'

  go

  --关闭shell

  sp_configure 'xp_cmdshell',0

  reconfigure

  wzbjz.codeplex.com

  go

  sp_configure 'show advanced options',0

  reconfigure

  go

0 0
原创粉丝点击