Find the latest version here.
One of the best things about Powershell and the community is the ability to easily find what others have done and improve upon it or tweak it for your own needs. This was the case with a script I found in the Veeam forums a few months back to backup a single VM using Powershell. It worked great (with a minor issue described below) but unfortunately was broken after upgrading to v7. I was able to identify the issues causing it to fail but was not able to rectify them all. Back to the forums I went and with a little help from the folks at Veeam we were back in business.
There is one ‘gotcha’ to this script. It relies on the fact that VMs are added to the job individually and not via some form of container such as datastore, resource pool, etc. The reason for this lies within the magic of the script itself. Basically what the script does is exclude all objects in the job except the VM you want to back up. If we exclude a container that holds the VM we want to back up then the exclusion overrides and nothing gets backed up. So as long as you create your jobs using individual VMs the script should work like a charm.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load Veeam snapin | |
Add-PsSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue | |
Clear-Host | |
Write-Host "VM must be explicitly defined in the job" | |
Write-Host "VM can not be inherited by a folder, datastore or other object or it will get excluded as well and job will be empty." | |
Write-Host "" | |
Write-Host "Always confirm job completion via Veeam BR Console" | |
Write-Host "" | |
# Check Veeam Version (Must be v7) | |
If ((Get-PSSnapin VeeamPSSnapin).Version.Major -ne 7) { | |
Write-Host "You must be running VBR v7 to run this script…Exiting" | |
Exit | |
} | |
# User Input | |
$jobName = Read-Host "Enter Job Name" | |
$vmName = Read-Host "Enter VM Name" | |
# Find the job that has our VM | |
$job = Get-VBRJob | ?{$_.Name -eq $jobName} | |
# Get all objects in job apart from our target VM | |
$execObjs = $job.GetObjectsInJob() | ?{$_.Name -ne $vmName} | |
# Exclude the objects from the job(*Note: this isn't removing the objects | |
# from the job) | |
Remove-VBRJobObject -Objects $execObjs | |
# Start the job only backing up the target VM | |
Start-VBRJob -Job $job | |
# Find the exclude job objects | |
$incObjs = $job.GetObjectsInJob() | ?{$_.Type -eq "Exclude"} | |
# Delete the exclude objects and re-add to job | |
foreach ($obj in $incObjs) { | |
$Excitem = $obj.GetObject().GetItem() | |
Add-VBRViJobObject -job $Job -Entities $Excitem | |
$obj.Delete() | Out-Null | |
} |
Great script :-), any chance you’ll post an updated version for Veeam 8? The script makes an error when it tries to put the excluded vm’s back in the job…
Hi Phil
I’m happy to say the script is no longer needed in v8 due to the addition of the Quick Backup feature. More info can be found here:
http://www.veeam.com/blog/8-gems-in-veeam-availability-suite-v8-part-3-quick-backup.html
Quick reply, thanks… 🙂 unfortunately I need it to backup a newly added vm (full backup), and this feature only supports vm’s that have already been backed up…
Excellent catch!
Script has been updated for v8 here:
http://blog.smasterson.com/2015/02/06/veeam-v8-backing-up-a-single-vm-with-powershell/
Pingback: Veeam v8 – Backing up a single VM with PowerShell | Shawn Masterson's Blog