Am I doing backups of all my VMs? 2016 Edition

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×

Note: Just like the original script, I had a first idea about a way to do these checks and you will still find traces of it in Veeam forums, however the ongoing discussion has lead to this updatedversion, and it’s really different from the original code, and much better. Kudos for Powershell code goes to my colleague Tom Sightler, if you find this script useful say thanks to him.

In 2012 I published a post with a Powershell script to be able to check all the available VM’s in a given vSphere environment, and verify that Veeam Backup & Replication was taking backups of all my VMs. Time to update the script to make it work with the latest versions of the two software.

Why you want this check

There are situations where it’s easy to verify that every virtual machine that needs to be backed up, it’s effectively protected. But if you are managing hundreds or thousands of VM’s, or you have a highly dynamic environment where VM creation and deletion is frequent, or there are many sysadmins working together, in all these situations there may be changes in the VM list, and if not all of these are configured in the backup jobs one by one, you can dangerously forget some of them… and find it out only when you would need a restore that you cannot complete.

To ease this problem, there is a preventive method as using containers instead of VM lists. If for example you use a resource pool as your backup object, or a datastore or the entire vCenter structure, VM list is created dynamically at every backup execution because the list is read from vCenter everytime. But what if a completely new resource pool or a datastore is created, but not added to the backup jobs? Or maybe someone of the admins have previously excluded a single VM from a backup job, maybe because it was only a test machine he didn’t not want to save, but then this machine became a production machine, and still was not protected.

The checking script

To solve these problems, you can run a Powershell script to check the status of your backups. The previous script was using some unsupported calls that have been since removed from Veeam Backup & Replication. But here it is the new and again functioning 2016 edition!

This script can be executed on the Veeam Server or from any remote workstation using the Standalone Console and the Connect-VBRServer cmdlet. The script looks for every vcenter and single ESXi registered in Veeam Backup & Replication, and retrieves the complete list of all existing virtual machines. No credential is needed as the script uses the same registered in Veeam Backup server itelf.

The script then checks for each of the VM’s if there is a backup (with Success or Warning result) in the last 24 hours. You can change this value by modifying the variable $HourstoCheck = 24

After you you run the script, the result will be like this:

Protectedvm1

Protected VMs are coloured in green, unprotected in red. This is a super-easy way to check which VMs are protected, and correct your omissions. By changing 24 hours value, you can go back in time to check non daily backups. or as in my case, there is a VM that is replicated daily. The original VM is already protected, but I’m not interested to have a backup also of the replica. So I can use the exclusion list also available in the options of the script, and re-run the script.

As explained in the script itself, to exclude VM’s from the report you can add VM names to be excluded as follows:

In my example, if I’ve used the default suffix “_replica” to name replicated VM’s, I can immediately excluse any replica from the script:

Protectedvm2

You can also exclude entire VM folders or entire Datacenters, if needed.

This is the complete script code, enjoy!

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×

5 thoughts on “Am I doing backups of all my VMs? 2016 Edition

  1. Very cool. I was looking for something like this and found your old script which didn’t work in v9.

    When running the script I get a bunch of errors like below, but at the end it looks like the output is working and correct.

    Exception calling “Add” with “2” argument(s): “Item has already been added. Key in dictionary:
    ‘9e170b9e-e533-4324-b07a-ef18771b8d18’ Key being added: ‘9e170b9e-e533-4324-b07a-ef18771b8d18′”
    + ForEach {$vms.Add(($_.FindObject().Id, $_.Id -ne $null)[0], @(“!”, $_.Path.S …
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentException

  2. Nice work, Thanks,
    working for me in Veeam 9.x. Can I send result via mail?
    thanks Again

    • Yes, you need to wrap the output in a powershell code that sends out emails, there are many around you can use as an example.

      • Finally I added HTML tags on $green and $red variables and send it via mail in HTML format.
        Ex:
        write-host -foregroundcolor green (($vm.Value[1]) + “” + ($vm.Value[2])) “is backed up in job:” $vm.Value[0]
        $green=$green + ($vm.Value[1]) + “” + ($vm.Value[2]) + “” + ($vm.Value[3]) + ” is backed up in job: ” + $vm.Value[0] +””
        } else {
        # write-host -foregroundcolor red (($vm.Value[1]) + “” + ($vm.Value[2]) + “” + ($vm.Value[3])) “is not found in any backup session in the last” $HourstoCheck “hours”
        $red=$red + ($vm.Value[1]) + “” + ($vm.Value[2]) + “” + ($vm.Value[3]) + ” is not found in any backup session in the last ” + $HourstoCheck + “hours” + “”
        }
        }

  3. Hi,

    In the last week, the script has given me false positives, machines that have backup but appear as unprotected. All those machines belong to the same host, those that are in other hosts do not give false positive. I’ve already rebooted that host, does anyone know what may be happening? Vcenter works normally.

Comments are closed.