About…

Using PowerShell to monitor Backups

We are using a RMM that has integrated BackupExec monitoring. I’ve found that this integrated monitoring was somewhat lacking. It gave us the current job status and that’s about it, Meaning there was not really a way to resolve issues pre-preemptively.

To resolve this we’ve created the following monitoring PowerShell script and integrated it into our RMM solution. For your convenience we’ll dissect the script so you can re-use this in your own solution or set it as scheduled job 🙂

We’ll start by importing the BEMCLI module which is included in BackupExec 2012 and up.

#Setting default CLI
import-module bemcli 

After importing the BEMCLI We’ll be able to use the cmdlets that get us the info we want, in this case “get-BEAlert” which gives us the current Alerts that have not been acknowledged within BackupExec

#Getting Alerts
$Alerts = Get-BEAlert

Now that we have the Alerts stored in a variable we wil loop through the contents of the alerts to find what we require;

#Looping through the alerts and writing the message to the console
foreach($Alert in $Alerts){
write-host $Alert.message
}

Now that we see that the messages are posted in the console we’d of course like a better overview.

#Looping through the alerts and setting them.
foreach($Alert in $Alerts){

switch ($Alert.Category)
{
JobWarning{$JobWarning = "TRUE - $($Alert.Message)" }
JobFailure{$JobFailure = "TRUE - $($Alert.Message)"}
JobCancellation{$JobCancellation = "TRUE - $($Alert.Message)" }
CatalogError{$CatalogError = "TRUE - $($Alert.Message)"}
SoftwareUpdateWarning{$SoftwareUpdateWarning = "TRUE - $($Alert.Message)"}
SoftwareUpdateError{$SoftwareUpdateError = "TRUE - $($Alert.Message)" }
DatabaseMaintenanceFailure{$DatabaseMaintenanceFailure = "TRUE - $($Alert.Message)"}
IdrCopyFailed{$IdrCopyFailed = "TRUE - $($Alert.Message)"}
BackupJobContainsNoData{$BackupJobContainsNoData = "TRUE - $($Alert.Message)" }
JobCompletedWithExceptions{$JobCompletedWithExceptions = "TRUE - $($Alert.Message)"}
JobStart{$JobStart = "TRUE - $($Alert.Message)"}
ServiceStart{$ServiceStart = "TRUE - $($Alert.Message)"}
ServiceStop{$ServiceStop = "TRUE - $($Alert.Message)"}
DeviceError{$DeviceError = "TRUE - $($Alert.Message)"}
DeviceWarning{$DeviceWarning = "TRUE - $($Alert.Message)"}
DeviceIntervention{$DeviceIntervention = "TRUE - $($Alert.Message)"}
MediaError{$MediaError = "TRUE - $($Alert.Message)"}
MediaWarning{$MediaWarning = "TRUE - $($Alert.Message)" }
MediaIntervention{$MediaIntervention = "TRUE - $($Alert.Message)"}
MediaInsert{$MediaInsert = "TRUE - $($Alert.Message)"}
MediaOverwrite{$MediaOverwrite = "TRUE - $($Alert.Message)"}
MediaRemove{$MediaRemove = "TRUE - $($Alert.Message)"}
LibraryInsert{$LibraryInsert = "TRUE - $($Alert.Message)"}
TapeAlertWarning{$TapeAlertWarning = "TRUE - $($Alert.Message)"}
TapeAlertError{$TapeAlertError = "TRUE - $($Alert.Message)" }
IdrFullBackupSuccessWarning{$IdrFullBackupSuccessWarning = "TRUE - $($Alert.Message)"}
LicenseAndMaintenanceWarning{$LicenseAndMaintenanceWarning = "TRUE - $($Alert.Message)"}
default{$OtherErr = "TRUE - $($Alert.Message)" }
}
}

Now if we put this all together the result would be;

<# .SYNOPSIS Gets BackupExec information and reports on Running Alerts - Only works on BackupExec 2012 and higher. .DESCRIPTION Using BEMCLI we retrieve data from BACKUPEXEC, including multiple types of alerts, LastRunTime, etc. Currently Alerts are generated for the following catagories: JobWarning JobFailure JobCancellation CatalogError SoftwareUpdateInformation SoftwareUpdateWarning SoftwareUpdateError DatabaseMaintenanceFailure IdrCopyFailed IdrFullBackupSuccess BackupJobContainsNoData JobCompletedWithExceptions JobStart ServiceStart ServiceStop DeviceError DeviceWarning DeviceIntervention MediaError MediaWarning MediaIntervention MediaInsert MediaOverwrite MediaRemove LibraryInsert TapeAlertWarning TapeAlertError IdrFullBackupSuccessWarning LicenseAndMaintenanceWarning .LINK http://www.cyberdrain.com #>

#Setting default CLI
i#Setting default CLI
import-module bemcli 
#Getting Alerts
$Alerts = Get-BEAlert

#Looping through the alerts and setting them.
foreach($Alert in $Alerts){

switch ($Alert.Category)
{
JobWarning{$JobWarning = "TRUE - $($Alert.Message)" }
JobFailure{$JobFailure = "TRUE - $($Alert.Message)"}
JobCancellation{$JobCancellation = "TRUE - $($Alert.Message)" }
CatalogError{$CatalogError = "TRUE - $($Alert.Message)"}
SoftwareUpdateWarning{$SoftwareUpdateWarning = "TRUE - $($Alert.Message)"}
SoftwareUpdateError{$SoftwareUpdateError = "TRUE - $($Alert.Message)" }
DatabaseMaintenanceFailure{$DatabaseMaintenanceFailure = "TRUE - $($Alert.Message)"}
IdrCopyFailed{$IdrCopyFailed = "TRUE - $($Alert.Message)"}
BackupJobContainsNoData{$BackupJobContainsNoData = "TRUE - $($Alert.Message)" }
JobCompletedWithExceptions{$JobCompletedWithExceptions = "TRUE - $($Alert.Message)"}
JobStart{$JobStart = "TRUE - $($Alert.Message)"}
ServiceStart{$ServiceStart = "TRUE - $($Alert.Message)"}
ServiceStop{$ServiceStop = "TRUE - $($Alert.Message)"}
DeviceError{$DeviceError = "TRUE - $($Alert.Message)"}
DeviceWarning{$DeviceWarning = "TRUE - $($Alert.Message)"}
DeviceIntervention{$DeviceIntervention = "TRUE - $($Alert.Message)"}
MediaError{$MediaError = "TRUE - $($Alert.Message)"}
MediaWarning{$MediaWarning = "TRUE - $($Alert.Message)" }
MediaIntervention{$MediaIntervention = "TRUE - $($Alert.Message)"}
MediaInsert{$MediaInsert = "TRUE - $($Alert.Message)"}
MediaOverwrite{$MediaOverwrite = "TRUE - $($Alert.Message)"}
MediaRemove{$MediaRemove = "TRUE - $($Alert.Message)"}
LibraryInsert{$LibraryInsert = "TRUE - $($Alert.Message)"}
TapeAlertWarning{$TapeAlertWarning = "TRUE - $($Alert.Message)"}
TapeAlertError{$TapeAlertError = "TRUE - $($Alert.Message)" }
IdrFullBackupSuccessWarning{$IdrFullBackupSuccessWarning = "TRUE - $($Alert.Message)"}
LicenseAndMaintenanceWarning{$LicenseAndMaintenanceWarning = "TRUE - $($Alert.Message)"}
default{$OtherErr = "TRUE - $($Alert.Message)" }
}
}

Now you can schedulde this script in your own RMM or sent e-mails based on the result.:) Happy Scripting!

Leave a Comment

(3 Comments)

  • Henk

    Nice! thanks, not using together with e-mail script to monitor backupexec.

    Tip: the title does not contain backupexec but only backup. maybe chance it?

  • Mike

    Any chance you’ve moved on from BackupExec… say, to… AppAssure or StorageCraft and have nifty PowerShell for those applications?

    • Kelvin Tegelaar

      I’ll actually cover these in the last of my new blog series about monitoring, it should be released by the end of this week. 🙂

  • Your email address will not be published. Required fields are marked *