http://www.cnblogs.com/top5/archive/2009/11/17/1604767.html

参考上面的博客

' =============== 局域网文件自动备份 VBS 脚本 =================
'
' 条件:10.97.1.X 开用户xcopy/xcopy 属于adminstrator
' 共享BACKUP 文件所在目录,使xcopy 用户完全控制!
' 运行后在管理进程中有2个进程:wscript.exe,ping.exe
' 以日期为log文件名称,只保留7天的日志
'
' =============================================================

Do While True
dim f,txtfile

Set f = CreateObject("Scripting.FileSystemObject")
set txtfile = f.opentextfile("D:\web\barcodeprinter\BACKUP\"&date&".txt",8,True)

'==== 判定7天前的log 文件是否存在,存在则删除!
If f.FileExists("D:\web\barcodeprinter\BACKUP\"&date-5&".txt") Then
   f.DeleteFile("D:\web\barcodeprinter\BACKUP\"&date-5&".txt")
end if
'====

txtfile.writeline("========= 实时备份开始:  "&date&" "&time&"==========")
txtfile.writeline(" ")
    Call backupfile(f,txtfile)
    WScript.Sleep 10000

txtfile.writeline("========= 实时备份结束:  "&date&" "&time&"==========")
txtfile.writeline("")

set f =nothing
set txtfile=nothing

Loop

'------------------------------------ 实时备份过程 -----------------------------------
sub backupfile(f,txtfile)
Dim Path,fso,net
num=1
do while num<10

if num=1 then
ip="10.97.1.3"&num
source_path="\\"&ip&"\产品数码跟踪"
target_path="BACKUP\barcodeprinter31.mdb"
end if

if num=2 then
ip="10.97.1.3"&num
source_path="\\"&ip&"\产品数码跟踪"
target_path="BACKUP\barcodeprinter32.mdb"
end if

if num=3 then
ip="10.97.1.3"&num
source_path="\\"&ip&"\产品数码跟踪"
target_path="BACKUP\barcodeprinter33.mdb"
end if

if num=4 then
ip="10.97.1.3"&num
source_path="\\"&ip&"\产品数码跟踪"
target_path="BACKUP\barcodeprinter34.mdb"
end if

if num=5 then
ip="10.97.1.3"&num
source_path="\\"&ip&"\qjcf_no1"
target_path="BACKUP\barcodeprinter35.mdb"
end if

if num=6 then
ip="10.97.1.3"&num
source_path="\\"&ip&"\产品数码跟踪(BarCodePrinter)"
target_path="BACKUP\barcodeprinter36.mdb"
end if

if num=7 then
ip="10.97.1.3"&num
source_path="\\"&ip&"\产品数码跟踪(BarCodePrinter)"
target_path="BACKUP\barcodeprinter37.mdb"
end if

if num=8 then
ip="10.97.1.3"&num
source_path="\\"&ip&"\产品数码跟踪"
target_path="BACKUP\barcodeprinter38.mdb"
end if

if num=9 then
ip="10.97.1.3"&num
source_path="\\"&ip&"\产品数码跟踪(BarCodePrinter)"
target_path="BACKUP\barcodeprinter39.mdb"
end if

'
ip="10.97.1.3"&num
source_path="\\"&ip&"\产品数码跟踪"
target_path="D:\WEB\barcodeprinter\BACKUP\barcodeprinter3"&num&".mdb"

'------------ ping 测试,网络通ping="T"; -------------------
Set FileSys   =   CreateObject("Scripting.FileSystemObject")
Set WShShell   =  CreateObject("WScript.Shell")   
RetCode   =   WShShell.Run("ping " &IP , 0, True )

if   RetCode   =   0   Then  ' ping 测试通过
ping="T"
else
ping="F"
end if
  
set filesys  = nothing
set wshshell = nothing

'------------ ping 结束 ------------------------------------

if ping="T" then

On Error Resume Next '出错不显示,执行下一条
Path="X:"
Set fso = CreateObject("Scripting.FileSystemObject")
Set net = CreateObject("WScript.Network")

If Not fso.DriveExists(fso.GetDriveName(Path)) Then
net.MapNetworkDrive Path,source_path,False,"xcopy","xcopy"
End If

Set file = fso.GetFile(Path&"\barcodeprinter.mdb")
file.Copy(target_path)

net.RemoveNetworkDrive Path,True

If Err.Number<>0 Then
txtfile.writeline("---  "&ip&"   备份失败! "&date&" "&time)
else
txtfile.writeline("---  "&ip&"   备份成功! "&date&" "&time&"--- OK!")
end if

else
txtfile.writeline("---  "&ip&"   网络不通! "&date&" "&time)
end if

set fso=nothing
set net=nothing

num=num+1
loop

end sub
'------------------------------------ 实时备份过程 -----------------------------------

这里备份的文件是barcodeprinter.mdb这个数据库文件,大家可以根据自己的实际情况进行代码修改

VBS 备份文件的更多相关文章

  1. oracle_自动备份用户数据,删除N天前的旧数据(非rman,bat+vbs)

    有时数据没有实时备份恢复那么高的安全性需求,但每天 ,或者定期备份表结构 和数据依旧是很有必要的,介绍一种方法 在归档和非归档模式均可使用的自动备份方法. 预期效果是备份用户下的数据含表结构,备份文件 ...

  2. 用批处理文件自动备份文件及文件夹,并自动删除n天前的文件

    原文:用批处理文件自动备份文件及文件夹,并自动删除n天前的文件 ---恢复内容开始--- 下是备份的批处理,添加到"计划任务"中,设定时间自动运行 复制代码 代码如下:@echo ...

  3. CMD批处理——forfiles命令使用,自动删除过期备份文件

    公司服务器用来备份数据的硬盘过段时间就会被备份文件占满,弄得我老是要登录到服务器去手工删除那些老的文件,有时忘记了就会导致硬盘空间不足而无法备份.因为只要保留最近几天的备份,如果可以做一个批处理让系统 ...

  4. 通过windows计划任务和Dos批处理备份文件

    目的: 1.计划每天每半小时备份1次,每天8点开始,执行12小时,20点结束. 2.定期删除历史备份文件,由于每天有多个时间段备份,删除前只保留当天最后一个备份. 说明: 由于删除的操作只有每天第一次 ...

  5. backup4:数据库自动备份,自动删除备份文件

    一:手写TSQL 脚本 1,自动备份 每周进行一次Database 的 Full Backup,设置 Schedule Interval 为Weekly use master go ) )+N'.ba ...

  6. C#调用vbs脚本实现Windows版Siri

    最近新加入,把自己一些有意思的小东西分享给大家,我是一个学生,代码写得少,哪里不规范,希望大家见谅. 这事我封装好的一个类,可以直接实例化对象之后,调用"对象.Talk()"方法, ...

  7. 在WinCC中通过VBS操作SQL Server2005

    在项目中需要在一定条件满足时,保存一些数据到数据库中,并可根据条件查询.考虑到WinCC6.2以后采用的就是SQL Server2005数据库,所以直接利用该数据库即可,通过SQL Server Ma ...

  8. 使用vbs脚本进行批量编码转换

    使用vbs脚本进行批量编码转换 最近需要使用SourceInsight查看分析在Linux系统下开发的项目代码,我们知道Linux系统中文本文件默认编码格式是UTF-8,而Windows中文系统中的默 ...

  9. SQL Server 通过备份文件初始化复制

    一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 搭建过程(Process) 注意事项(Attention) 疑问(Questions) 参考文 ...

随机推荐

  1. Flink从入门到放弃(入门篇4) DataStreamAPI

    戳更多文章: 1-Flink入门 2-本地环境搭建&构建第一个Flink应用 3-DataSet API 4-DataSteam API 5-集群部署 6-分布式缓存 7-重启策略 8-Fli ...

  2. C#工具:ASP.NET MVC单例模式(懒汉)实现文件上传

    1.SingletonConfigRead帮助类 using System; using System.Collections.Generic; using System.IO; using Syst ...

  3. oracle学习笔记(三) DCL 数据控制语言与 DDL 数据定义语言

    DCL 数据控制语言 Data control language 之前说过的授权和收权利语句 grant, revoke DDL 数据定义语言 Data define language create ...

  4. Spring Boot 整合 rabbitmq

    一.消息中间件的应用场景 异步处理 场景:用户注册,信息写入数据库后,需要给用户发送注册成功的邮件,再发送注册成功的邮件. 1.同步调用:注册成功后,顺序执行发送邮件方法,发送短信方法,最后响应用户 ...

  5. hash一致性

    参照:https://www.cnblogs.com/moonandstar08/p/5405991.html 参照:http://www.cnblogs.com/haippy/archive/201 ...

  6. Spring中关于AOP的实践之概念

    一.什么是AOP AOP:也称作面向切面编程 在分享几个概念执行我想先举个栗子(可能例子举得并不是特别恰当): 1.假如路人A走在大街上,被一群坏人绑架了: 2.警察叔叔接到报警迅速展开行动:收集情报 ...

  7. Yii2设计模式——单例模式

    应用举例 在Yii.php中: require __DIR__ . '/BaseYii.php'; // Yii框架的帮助类,提供框架基本的功能 class Yii extends \yii\Base ...

  8. 视频文件列表hover添加视频播放按钮

    默认效果图: 鼠标hover效果: 代码如下: <!DOCTYPE html> <html> <head> <meta charset="UTF-8 ...

  9. Python绘图与可视化

    Python有很多可视化工具,本篇只介绍Matplotlib. Matplotlib是一种2D的绘图库,它可以支持硬拷贝和跨系统的交互,它可以在Python脚本.IPython的交互环境下.Web应用 ...

  10. Kotlin 扩展——省略findViewById

    现在 Kotlin 安卓扩展插件能够提供与这些开源库功能相同的体验,不需要添加任何额外代码. import kotlinx.android.synthetic.main.activity_main.* ...