區域網路檔案自動備份 VBS 指令碼

來源:互聯網
上載者:User
' =============== 區域網路檔案自動備份 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這個資料庫檔案,大家可以根據自己的實際情況進行代碼修改

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.