HiperLogic

Virtualization, High Performance Computing, Healthcare IT, Enterprise Computing

Checking if all VMs are Backed up using Veeam and PowerCLI

Veeam Backup has an option to write the last backup time to a vCenter attribute. This is a nice feature that enables anyone using the VMware VIC client to see the last time a VM was backed up.

This feature makes it easy to write a script to ensure all VMs are backed up by querying this attribute with PowerCLI. Veeam emails you the status of all VMs it knows about ( that are in backup jobs ), but it is possible someone could add a VM that does not get added to your existing Veeam backup jobs.

The script to check for this issue is below.

1. Modify the script below to have the name of your vCenter server in $vCenterServer
2. Configure your Veeam Backup job to write to the “Backup” attribute on completion ( The default is Notes attribute, which is often used by Admins for other items ).
3. This script assumes that every VM is backed up at least once a day.
4. Run this script at the PowerCLI command prompt. See this 5 minute guide to PowerCLI to get started.

function get-backedup ($vm)
{
# This should be one line
$val = $vm.CustomFields |where {$_.key -eq "Backup" } | select -Property Value
$today = Get-Date -Format "M/d/yyyy"
$backupDate = $val.Value

return ( $backupDate -like "*$today*" )

}

Connect-VIServer $vCenterServer 

$vms = get-vm
foreach ($vm in $vms)
{
  if (get-backedup($vm)) {
      write-host -foregroundcolor green "$vm is backed up"
  } else {
      write-host -foregroundcolor red "$vm is NOT backed up"
  }
}

Tags: ,

© 2006-2010 HiperLogic, LLC.  |  Serving the Ann Arbor, Southeast Michigan, and Ohio region  |  (888)-268-3930  |