VB如何远程备份sqlserver数据库到本地机中

来源:互联网 发布:淘宝怎么退款申请 编辑:程序博客网 时间:2024/04/30 04:28

方法:

(1)将数据备份在远程的服务器中。
(2)远程共享某个目录
(3)将远程数据备份文件拷贝到本地机中
(4)清除远程共享的目录

这里主要用到的是sqlserver中内部的函

1.清除老的c:/temp2的文件,并新建c:/temp2'文件
cnn0.Execute "exec master..xp_cmdshell 'rd c:/temp2'"
cnn0.Execute "exec master..xp_cmdshell 'md c:/temp2'"

2.共享目录:
cnn0.Execute "exec master..xp_cmdshell 'net share SQLDATABACK2=C:/temp2'"

3.备份文件
cnn0.Execute "backup database " & s_db_name & " to disk='c:/temp2/" & Date & ".dat'"

4.远程复制到指定目录
fso.copyfile "//" & serverName & "/SQLDATABACK2/" & Date & ".dat", Trim(Text1), True

5.清理文件。
cnn0.Execute "exec master..xp_cmdshell 'net share SQLDATABACK2 /delete'"
cnn0.Execute "exec master..xp_cmdshell 'rd c:/temp2 /s/Q'"

 

原创粉丝点击