# Author: Heinrich Moser, www.moware.at, heinrich.moser.jun@moware.at # Version: 1.0, 2007-11-26 # Checks if there is a file backup??.log with todays date in the # specified directory. Checks if there are the specified number of # "Sicherung abgeschlossen ..." and "Überprüfung # abgeschlossen ..."-lines. # Configure here $LOGFILEDIR = "C:\Dokumente und Einstellungen\Administrator\Lokale Einstellungen\Anwendungsdaten\Microsoft\Windows NT\NTBackup\data" $NUMBER_TASKS = 2 # number of backup tasks (example: Exchange and SystemState = 2) $SMTPSERVER = "localhost" $MAILFROM = "heinrich.moser.jun@moware.at.invalid" $MAILTO = "heinrich.moser.jun@moware.at.invalid"; $MAILSUBJECT = "Error during ntbackup"; $BACKUPCOMPLETED = "Sicherung abgeschlossen" # "Backup completed" line in the log file in your system language $VERIFYCOMPLETED = "Überprüfung abgeschlossen" # "Verify completed" line in the log file in your system language $ERROR = "Fehler" # "Error" in your system language # Send mail and show message function Alert { Write-Warning $args[0] $sc = new-object Net.Mail.SmtpClient -arg "$SMTPSERVER" $sc.Send($MAILFROM, $MAILTO, $MAILSUBJECT, $args[0]) exit 1 } Trap [Exception] { Alert $($_.Exception.GetType().FullName + " in ntbackup-logcheck: " + $_.Exception.Message) } # find file with todays date $today = $null; foreach ($file in get-childitem $LOGFILEDIR\backup??.log) { if ($file.LastWriteTime.Date -eq [DateTime]::Now.Date) { $today = $file break } } if ($today -eq $null) { Alert "No backup file with today's date found!" } # open file and count lines $iBackup = (Get-Content $today | Select-String -SimpleMatch "$BACKUPCOMPLETED" | Measure-Object -Line).Lines $iVerify = (Get-Content $today | Select-String -SimpleMatch "$VERIFYCOMPLETED" | Measure-Object -Line).Lines $iErrors = (Get-Content $today | Select-String -SimpleMatch "$ERROR" | Measure-Object -Line).Lines if ($iErrors -gt 0) { Alert "Error found in logfile." } if (($iBackup -ne $NUMBER_TASKS) -or ($iVerify -ne $NUMBER_TASKS)) { Alert "Incomplete backup. $NUMBER_TASKS entries expected, $iBackup/$iVerify found." } Write-Host "Everything is OK." # don't send a mail