VMware Backup with PowerCLI and Veeam

My primary backup drive for my virtual machine backup toasted on me so I had to recreate all of my backup jobs. I’ve been using Veeam’s backup product for VMware and it couldn’t be easier to use. I’ve known that it included a set of PowerShell cmdlets but I had never really looked at them before.  I decided this would be a great opportunity.

One of my backup goals, that I’ll describe today, was to grab all VMs in a particular datastore and backup them up to a local external drive. The current version of Veeam doesn’t allow you to specify a datastore as a container. Although I didn’t use it, you are supposed to be able to specify an ESX host, which will back up all machines. Or you need to specify a comma separated list of virtual machines. In my case, I wanted all VMs on datastore2. But what are they? PowerCLI to the rescue. First off, your VM host must be connected and not in maintenance mode. For my purposes, I like having the virtual machines themselves powered off. Using Get-VM I can find all machines on the required datastore.

PS C:\> get-vm -Datastore datastore2

Name                 PowerState Num CPUs Memory (MB)
—-                 ———- ——– ———–
MyCompany Windows 7  PoweredOff 1        512
R2 Core RODC         PoweredOff 1        1024
MyCompany Vista      PoweredOff 1        768
MyCompany XP         PoweredOff 1        384
MyCompany2003        PoweredOff 1        384
Research Member S… PoweredOff 2        1024

All I need are the names so I pop them into a variable.

PS C:\> get-vm -Datastore datastore2 | foreach {$v+=$_.name}
PS C:\> $v
MyCompany Windows 7
R2 Core RODC
MyCompany Vista
MyCompany XP
MyCompany2003
Research Member Server R2

Armed with this I can now invoke the Add-VBRBackupJob cmdlet from Veeam.

PS C:\> Add-VBRBackupJob -Name "Dstore2_Backup" -Type VDDK –mode "san;nbd" –Folder "g:\datastore2" -objects $v -host "My Computer" –FileName "dstore2"

This command will create a backup job called Dstore2_Backup using the VMware vStorage API to backup all VM objects to G:\Datastore2 on “My Computer”.  As I continue to poke around with these cmdlets, I’ll be sure to share.