备份Robocopy的VBS脚本

时间:2016-08-12 11:22:00

标签: vbscript

我有一个用于备份rc的VBS脚本,这个脚本早先工作但现在没有。

StrDatum = Day(Now) & "." & Month(Now) & "." & Year(Now)
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const OverwriteExisting = True
StrRobocopyOptions= "/E /B /R:0 /W:0 /V /NP"
StrConfigFilePath = "C:\Tools\Backup\backupJobs.cfg"
StrRobocopyExePath = "C:\Program Files\Windows Resource Kits\Tools\robocopy.exe"

strServerBackupPath = "\\midaserver\KNJIGOVODSTVO"
StrServweLogPath = "\\midaserver\KNJIGOVODSTVO\logs"
strComputer = "."

Set objShell = CreateObject ("wscript.shell")
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 

Set colComputer = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")

For Each objComputer in colComputer
    strComputerName = objComputer.Caption
Next




Set objFSO = CreateObject ("Scripting.FileSystemObject")
Set objReadConfFile = objFSO.OpenTextFile (StrConfigFilePath,ForReading)
"Set objRobocopyStatusWriter = objFSO.OpenTextFile (strServerBackupPath & "\\" & strComputerName & "\copy_status_tst.log",ForWriting,OverwriteExisting) 
objRobocopyStatusWriter.Write "Started > " & StrDatum & " > "
Do Until (objReadConfFile.AtEndOfStream = True)

strSourceFolder = Trim(objReadConfFile.ReadLine)
strCommand = StrRobocopyExePath & " " & StrRobocopyOptions & " " & """" & strSourceFolder & """" & " " & """" & strServerBackupPath & "\" & strComputerName & "\" & imeDira(strSourceFolder) & """"

Set objRobocopyLogWriter = objFSO.OpenTextFile (StrServweLogPath & "\" & strCompuerName & "-" & imeDira(strSourceFolder) & ".log" ,ForWriting,OverwriteExisting)

Set objScriptExec = objShell.Exec (strCommand)

    Do While Not objScriptExec.StdOut.AtEndOfStream
        strLinija = objScriptExec.StdOut.ReadLine
        objRobocopyLogWriter.WriteLine strLinija
    loop

strCommand = "" 
objRobocopyLogWriter.Close

Loop
objRobocopyStatusWriter.Write "Finished"
objRobocopyStatusWriter.Close
Function imeDira(putanja)
    arrSubIme = Split(putanja,"\")
    imeDira = arrSubIme(UBound(arrSubIme))
End Function

当我运行它时,会出现下一个错误:

脚本:\ mida5 \ c $ \ Backup \ BackupiListFolders.vbs 行:29 Char:1 错误:找不到路径 代码:800A004C 来源:Microsoft VBScript运行时错误

1 个答案:

答案 0 :(得分:0)

robocopy为您进行日志记录。

  <UICollectionViewDataSource,UICollectionViewDelegate>