Scripting Veeam SureBackup with tag-based backup jobs – Workaround

Scripting Veeam SureBackup with tag-based backup jobs – Workaround

This post might be interesting for anyone who scripts Veeam SureBackup in any form. In this case you probably use the script of Luca Dell’Oca: How can you test 1000 VMs with Veeam SureBackup? This script is great and works just fine! A limitation here is that it is not possible to change default timeouts for boot and application initialization. Honestly this was a limitation in v9 and before. Basically this can be done since v10. With this version there are new PowerShell cmdlets for SureBackup, I show later. The problem is, VM(s) to test must have been added explicitly to the backup job. Find a workaround in this post for scripting Veeam SureBackup with tag- or other container based backup jobs. Special thanks to Andreas Lesslhumer for this great idea!

The problem is, that the cmdlet Get-VBRJobObject to get objects for SureBackup does not support tag- or other container based VM selection. Such containers can be Hosts, Datastores or Folders. The idea to overcome this is to add VM you want to test temporary to the backup job explicitly. Then it is possible to add VM to SureBackup even the original job uses for example tag-based VM selection. When this is done, VM can be removed from job again. Probably some script snippets will illustrate this better.

Scripting SureBackup code snippets

First, set startup options as desired.

$VSBOpt = New-VBRSureBackupStartupOptions -AllocatedMemory 99 -EnableVMHeartbeatCheck:$false -EnableVMPingCheck:$false -MaximumBootTime 1200 -ApplicationInitializationTimeout 1200 

Following screenshot illustrates the command. For more details about this options, check my post.

scripting veeam surebackup with powershell

To continue, you need the VM name and the backup job of your VM to test with SureBackup. Proper objects must be created.

$TestVMObject = Find-VBRViEntity -Name $TestVMname
$TestVMVbrJob = Get-VBRJob -Name $TestVMJobname

With this data you can add VM temporary to the job.

Add-VBRViJobObject -Job $TestVMVbrJob -Entities $TestVMObject

Next, get this added VM as correct object for further processing. Here it is important to just select backup objects with type “Include”. This is because in some configurations other object types exists. For example when a VM is explicitly added to guest processing (for custom configuration), you would see type “VssChild”. This type cannot be used here.

$VbrJobObject = Get-VBRJobObject -Job $TestVMVbrJob -name $TestVMObject.Name | Where-Object {$_.type -eq "Include"}

This new object can now be combined with the startup options to create a SureBackup-VM object.

$SbVMs += New-VBRSureBackupVM -VM $VbrJobObject -StartupOptions $VSBOpt

After this command, VM can be removed form job again.

Remove-VBRJobObject -Objects $VbrJobObject -Completely

Now create the application group.

$AppGroup = Add-VBRViApplicationGroup -Name $AppGroupName -VM $SbVMs

Because existing backup job is temporary changed, attention should be paid here! If VMs are added explicitly to selection of backup jobs, you should check before adding VM to the job. And just remove it if you really added it before!

Final Tip

[update] Finally I published a scripted solution for How to SureBackup a lot of VMs. This script includes the workaround of this post.

For users of the script of Luca Dell’Oca, keep in mind, in order to use these described new commands you need the backup job as parameter. This was not necessary with the old cmdlets. Because of this, Luca’s script uses a hashtable with VM name as key. I personally think it is a good idea to replace this hashtable by an array that includes the job name. Works at least fine for me.


Leave a Reply

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