07. 12. 2022 Alessandro Romboli Business Service Monitoring, NetEye, Unified Monitoring

Monitoring Veeam Backup & Replication

Scenario

Veeam Backup & Replication product is widely used for backuping virtual machines, primary hosted on VMware vSphere infrastructure.

It could also backup physical machines through dedicated agents.

It’s very important to keep the backup status monitored: it would be nice to get the backup status through the Icinga2 agent in an easy way.

PowerShell scripting

Fortunately, Veeam provides us a powerful PowerShell interface and a huge set of commands which can be used to control jobs and get the actual status:

https://helpcenter.veeam.com/docs/backup/powershell/getting_started.html?ver=110

Our main goal is to write a script which will get the overall backup job status, possibly without specifying the Veeam backup job name list.

First of all, there is a command Get-VBRJob which returns the information about all the existing Veeam backup jobs: note that this command is limited to the backup to disks and it will skip the backup to tape jobs. In our monitoring script we must skip the disabled jobs, so we can filter the command as:

Get-VBRJob|where {$_.IsScheduleEnabled}

There are a couple of values in the command result which are very important:

$($job.findlastsession()).State

which will have the value “Working” for running backup jobs and “Idle” for continuous ones. We must skip both of them because they won’t return a valid status.

$job.GetLastResult()

which will return the result status of the last completed job.

Using a global variable to store the overall status of the backup to disk jobs (0 success, 1 warning, 2 failure), a first PowerShell check routine will be:

# Global variables
[int]$globalstatus = 0
[string]$globaljobs = ""

# Veeam Backup & Replication disk job status check
$jobs = Get-VBRJob|where {$_.IsScheduleEnabled}

foreach ($job in $jobs)
{
	$status = $job.GetLastResult()
	$state = $($job.findlastsession()).State

	if(($state -eq "Working") -or ($state -eq "Idle")){continue}

	if ($status -eq "Failed")
	{
		$globalstatus = 2
		$globaljobs += $job.Name
		$globaljobs += " "
	}

	if ($status -ne "Success")
	{
		if (-not ($globalstatus)) { $globalstatus = 1 }
		$globaljobs += $job.Name
		$globaljobs += " "
	}
}

This routine will concatenate the job name of the ones in Warning or in Error state in a string $globaljobs

Backup to tape

As said at the beginning of this blog, the Veeam backup to Tape uses different PowerShell commands and also the status variables are a little different from the previous ones.

The Veeam global status command for Tape jobs is Get-VBRTapeJob.

The last State and Status are directly exposed into the result, without the usage of additional functions:

$job.LastResult
$job.LastState

We can use the same logic as the previous routine to get the overall job status.

Combine all in a single PowerShell script

We can build a single PowerShell script to get the overall Veeam backup job status both for disk and tape jobs.

This script can be easily called by Icinga2 monitoring agent once a day or more frequently to get a quick overview of the Veeam backup status.

# Adding required SnapIn

Import-Module  Veeam.Backup.PowerShell -DisableNameChecking

# Global variables
[int]$globalstatus = 0
[string]$globaljobs = ""
$ErrorActionPreference = 'SilentlyContinue'

# Veeam Backup & Replication job status check
$jobs = Get-VBRJob|where {$_.IsScheduleEnabled}

foreach ($job in $jobs)
{
	$status = $job.GetLastResult()
	$state = $($job.findlastsession()).State

	if(($state -eq "Working") -or ($state -eq "Idle")){continue}

	if ($status -eq "Failed")
	{
		$globalstatus = 2
		$globaljobs += $job.Name
		$globaljobs += " "
	}

	if ($status -ne "Success")
	{
		if (-not ($globalstatus)) { $globalstatus = 1 }
		$globaljobs += $job.Name
		$globaljobs += " "
	}
}

# Veeam Backup & Replication TAPE job status check
$jobs = Get-VBRTapeJob|where {$_.Enabled}

foreach ($job in $jobs)
{
	$status = $job.LastResult
	$state = $job.LastState

	if(($state -eq "Working") -or ($state -eq "Idle")){continue}

	if ($status -eq "Failed")
	{
		$globalstatus = 2
		$globaljobs += $job.Name
		$globaljobs += " "
	}

	if ($status -ne "Success")
	{
		if (-not ($globalstatus)) { $globalstatus = 1 }
		$globaljobs += $job.Name
		$globaljobs += " "
	}
}

if($globalstatus -eq 2)
{
	Write-Host "CRITICAL! At least one backup job in error: $globaljobs"
} 
else
{
	if($globalstatus)
	{
		Write-Host "WARNING! At least one backup job in warning: $globaljobs"
	}
	else
	{
		Write-Host "OK! All backup jobs completed successfully."
	}
}

exit ($globalstatus)
Alessandro Romboli

Alessandro Romboli

Site Reliability Engineer at Würth Phoenix
My name is Alessandro and I joined Würth-Phoenix early in 2013. I have over 20 years of experience in the IT sector: For a long time I've worked for a big Italian bank in a very complex environment, managing the software provisioning for all the branch offices. Then I've worked as a system administrator for an international IT provider supporting several big companies in their infrastructures, providing high availability solutions and disaster recovery implementations. I've joined the VMware virtual infrastructure in early stage, since version 2: it was one of the first productive Server Farms in Italy. I always like to study and compare different technologies: I work with Linux, MAC OSX, Windows and VMWare. Since I joined Würth Phoenix, I could also expand my experience on Firewalls, Storage Area Networks, Local Area Networks, designing and implementing complete solutions for our customers. Primarily, I'm a system administrator and solution designer, certified as VMware VCP6 DCV, Microsoft MCP for Windows Server, Hyper-V and System Center Virtual Machine Manager, SQL Server, SharePoint. Besides computers, I also like photography, sport and trekking in the mountains.

Author

Alessandro Romboli

My name is Alessandro and I joined Würth-Phoenix early in 2013. I have over 20 years of experience in the IT sector: For a long time I've worked for a big Italian bank in a very complex environment, managing the software provisioning for all the branch offices. Then I've worked as a system administrator for an international IT provider supporting several big companies in their infrastructures, providing high availability solutions and disaster recovery implementations. I've joined the VMware virtual infrastructure in early stage, since version 2: it was one of the first productive Server Farms in Italy. I always like to study and compare different technologies: I work with Linux, MAC OSX, Windows and VMWare. Since I joined Würth Phoenix, I could also expand my experience on Firewalls, Storage Area Networks, Local Area Networks, designing and implementing complete solutions for our customers. Primarily, I'm a system administrator and solution designer, certified as VMware VCP6 DCV, Microsoft MCP for Windows Server, Hyper-V and System Center Virtual Machine Manager, SQL Server, SharePoint. Besides computers, I also like photography, sport and trekking in the mountains.

Leave a Reply

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

Archive