Analyze Robocopy Log
AnalyzeRobocopyLog.vbs è uno script WSH che analizza e riassume in pochi secondi i lunghissimi log generati da robocopy riportando e mettendo in evidenza gli errori riscontrati e le altre informazioni utili al controllo della corretta esecuzione del processo di backup.
Come input è necessario fornire il percorso completo della cartella contente i file di log da sottoporre ad analisi.
Lo script va eseguito per mezzo del prompt dei comandi utilizzando il motore WSH “cscript.exe”, la sintassi è la seguente:
cscript.exe AnalyzeRobocopyLog.vbs "cartella_sorgente"
Esempio:
cscript.exe AnalyzeRobocopyLog.vbs "c:\logs"
Per reindirizzarne l'output in un file di testo è sufficiente eseguirlo in questo modo:
cscript.exe AnalyzeRobocopyLog.vbs "c:\logs" > output.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | ' *************************************************************************************** ' *** ' *** Scriptname: AnalyzeRobocopyLog.vbs ' *** ' *** Purpose: Scans robocopy log files for summaries and errors. Generates consolidated list ' *** and prints to screen. Screen output can be redirected to a file if necessary. ' *** ' *** Requirements: Log files have to be in a single folder. ' *** ' *** Usage: Run the following command for usage: "cscript AnalyzeRobocopyLog.vbs /?" ' *** ' *** Author: Dirk Pelzer ' *** ' *** Version: 2.0 ' *** ' *** History: 23.09.04 (dp) Initial version (1.0) ' *** 06.10.04 (dp) Added code to read arguments from the command line (2.0) ' *** ' *** (c) 2004 Dirk Pelzer. All rights reserved. Use at your own risk. ' *** ' *************************************************************************************** Option Explicit '************************************************* ' Variables '************************************************* Dim intRet Dim aryFileList Dim strFolder Dim strReadBuffer Dim aryReadBuffer Dim strFilename Dim i, j Dim strSummary Dim oArgs '************************************************* ' Constants '************************************************* Const DOUBLESPACE = " " Const DEFAULTSOURCEDIR = "C:\Logs" '************************************************* ' Indicate script start '************************************************* wscript.echo "***************************" wscript.echo "* Anylyzing Robocopy logs *" wscript.echo "***************************" wscript.echo '************************************************* ' Read args from command line '************************************************* Set oArgs = WScript.Arguments If oArgs.Count = 0 Then wscript.echo "No source folder specified. Using default " & DEFAULTSOURCEDIR & "." & vbCRLF strFolder = DEFAULTSOURCEDIR Else strFolder = oArgs(0) End If Set oArgs = Nothing '************************************************* ' Figure out if user requested help '************************************************* Select case uCase(strFolder) Case "?" Usage Case "/?" Usage Case "HELP" Usage Case "-?" Usage Case "H" Usage End Select '************************************************* ' Retrieve list of files from a given folder '************************************************* intRet = EnumerateFiles(strFolder, aryFileList) Select Case intRet Case 1 wscript.echo "Error: Specified folder does not exist." wscript.echo " Please verify that " & strFolder & " really exists" & vbCRLF & _ " and you have sufficient permissions." & vbCRLF wscript.echo "Script aborted." wscript.quit(1) Case 2 wscript.echo "Error: The specified folder was empty." wscript.echo " Please verify that " & strFolder & " contains" & vbCRLF & _ " robocopy logs and you have sufficient permissions." & vbCRLF wscript.echo "Script aborted." wscript.quit(1) End Select '************************************************* ' Loop through log files and parse for keywords '************************************************* strSummary = "" For i = 0 to uBound(aryFileList) strFileName = strFolder & "\" & aryFileList(i) 'wscript.echo "strFileName = " & strFileName intRet = ReadFile(strFileName, strReadBuffer) 'wscript.echo strReadBuffer strSummary = strSummary & vbCRLF strSummary = strSummary & " --- START ---" & vbCRLF strSummary = strSummary & DOUBLESPACE & aryFileList(i) & vbCRLF If intRet = 0 Then 'Valid buffer. Split up individual lines aryReadBuffer = split(strReadBuffer, vbCRLF) For j = 0 to ubound(aryReadBuffer) ' Parse for known keywords If instr(aryReadBuffer(j), "Started :") > 0 Then strSummary = strSummary & aryReadBuffer(j) & vbCRLF If instr(aryReadBuffer(j), "Source :") > 0 Then strSummary = strSummary & aryReadBuffer(j) & vbCRLF If instr(aryReadBuffer(j), "Dest :") > 0 Then strSummary = strSummary & aryReadBuffer(j) & vbCRLF If instr(aryReadBuffer(j), "Options :") > 0 Then strSummary = strSummary & aryReadBuffer(j) & vbCRLF If instr(aryReadBuffer(j), "Total Copied Skipped") > 0 Then strSummary = strSummary & aryReadBuffer(j) & vbCRLF If instr(aryReadBuffer(j), "Dirs :") > 0 Then strSummary = strSummary & aryReadBuffer(j) & vbCRLF If instr(aryReadBuffer(j), "Files :") > 0 Then strSummary = strSummary & aryReadBuffer(j) & vbCRLF If instr(aryReadBuffer(j), "Bytes :") > 0 Then strSummary = strSummary & aryReadBuffer(j) & vbCRLF If instr(aryReadBuffer(j), "Times :") > 0 Then strSummary = strSummary & aryReadBuffer(j) & vbCRLF If instr(aryReadBuffer(j), "Ended :") > 0 Then strSummary = strSummary & aryReadBuffer(j) & vbCRLF If instr(aryReadBuffer(j), "Speed :") > 0 Then strSummary = strSummary & aryReadBuffer(j) & vbCRLF If instr(aryReadBuffer(j), " ERROR ") > 0 Then strSummary = strSummary & aryReadBuffer(j) & vbCRLF Next End If strSummary = strSummary & " --- END ---" & vbCRLF strSummary = strSummary & vbCRLF Next wscript.echo " RESULT" wscript.echo "====================" wscript.echo wscript.echo strSummary wscript.echo wscript.echo "Script completed successfully" '************************************************* ' ReadFile '************************************************* Function ReadFile(strFileName, strReadBuffer) ' Returns the content of a specified file in strReadBuffer Const ForReading = 1, ForWriting = 2 Dim fso, f Set fso = CreateObject("Scripting.FileSystemObject") If NOT (fso.FileExists(strFileName)) Then ReadFile = 1 'Specified file does nor exist Set fso = Nothing Exit Function End If Set f = fso.OpenTextFile(strFileName, ForReading) strReadBuffer = f.ReadAll if len(strReadBuffer)> 0 Then ReadFile = 0 'File read successfully Else ReadFile = 2 'File was empty End if Set f = Nothing Set fso = Nothing End Function '************************************************* ' EnumerateFiles '************************************************* Function EnumerateFiles(strFolder, aryFileList) ' Returns an array of all files in a specified folder ' Return code = 0: success ' Return code = 1: specified folder does not exist ' Return code = 2: no files found Dim strFileList Dim fso, f, f1, fc, s strFileList = "" Set fso = CreateObject("Scripting.FileSystemObject") If NOT (fso.FolderExists(strFolder)) Then EnumerateFiles = 1 'Specified folder does not exist Set fso = Nothing Exit Function End If Set f = fso.GetFolder(strFolder) Set fc = f.Files For Each f1 in fc strFileList = strFileList & f1.name & ";" 'wscript.echo "strFileList = " & strFileList Next If right (strFileList, 1) = ";" Then strFileList = left(strFileList, len(strFileList)-1) aryFileList = split (strFileList, ";") If uBound(aryFileList) >= 0 then EnumerateFiles = 0 'Files found Else EnumerateFiles = 2 'No files found End If Set fc = nothing Set f = nothing Set fso = nothing End Function '************************************************* ' Usage '************************************************* Sub Usage wscript.echo wscript.echo "Usage:" wscript.echo "~~~~~~" & vbCRLF wscript.echo "cscript " & WScript.ScriptName & " [sourcepath]" & vbCRLF wscript.echo " where [sourcepath] is the full path to the log files to be analyzed." & vbCRLF wscript.echo "If no [sourcepath] is specified, the default path " & DEFAULTSOURCEDIR & " is used." & vbCRLF wscript.echo "Example: cscript " & WScript.ScriptName & " c:\Temp" wscript.quit (0) End Sub |
Print This • Email this • Twit This! • Add to del.icio.us • Share on Facebook • Digg This! • Stumble It! • AddThis! • Share on Segnalo Alice • Share on OKNotizie