-
- Enthusiast
- Posts: 63
- Liked: 8 times
- Joined: Jan 16, 2014 11:12 pm
- Full Name: Jon Dufour
- Contact:
Add VM's to Exclusions list
I've been trying to figure out how to add a VM to the Exclusion list in a job with PowerShell and the cmdlet Remove-VBRJobObject seems to be the closest thing to do that based on searching but that only works if the job is based on individual VM's. I want to directly add a VM to the exclusion list.
Like a lot of others my jobs are based on containers (folders) in VMware. I can still go into the job from the gui and add a vm exclusion which does work.
My end goal is to create a PS script that excludes all the vm's in a folder but the one I want to make a quick backup of.
Like a lot of others my jobs are based on containers (folders) in VMware. I can still go into the job from the gui and add a vm exclusion which does work.
My end goal is to create a PS script that excludes all the vm's in a folder but the one I want to make a quick backup of.
-
- VP, Product Management
- Posts: 6036
- Liked: 2863 times
- Joined: Jun 05, 2009 12:57 pm
- Full Name: Tom Sightler
- Contact:
Re: Add VM's to Exclusions list
I know it's a little counter intuitive, but you have to add the object to the job via Powershell before you can use the Remove-VBRJobObject cmdlet to exclude it. Very simple example:
So you'd want to have code that enumerates the VMs in the folder, runs through adding them individually to the job, then immediately using Remove-VBRJobObject to explicitly exclude them from the job.
Code: Select all
asnp "VeeamPSSnapIn" -ErrorAction SilentlyContinue
$jobname = "<Job_Name>"
$vmname = "<VM_Name>"
Add-VBRViJobObject -Job $jobname -Entities (Find-VBRViEntity -Name $vmname)
Get-VBRJobObject -Job $jobname -Name $vmname | Remove-VBRJobObject
-
- Enthusiast
- Posts: 63
- Liked: 8 times
- Joined: Jan 16, 2014 11:12 pm
- Full Name: Jon Dufour
- Contact:
Re: Add VM's to Exclusions list
That did it! You were exactly right, I would have never thought to add the object to the job first and then exclude it, thanks Tom!
-
- Product Manager
- Posts: 20677
- Liked: 2382 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Add VM's to Exclusions list
I've scripted the exclusion process previously, but the used approach seems to have been overcomplex. You can, probably, disregard the part about creating CObjectInJob and just take the one about enumerating VMs in folder. Thanks.
-
- Enthusiast
- Posts: 63
- Liked: 8 times
- Joined: Jan 16, 2014 11:12 pm
- Full Name: Jon Dufour
- Contact:
Re: Add VM's to Exclusions list
I had done some searching and didn't find that post, perhaps due to the misspellings in the title, "Backup single VM within job witch backup foldre"
That is super close to what I did and parts of this are from scripts others have done;
That is super close to what I did and parts of this are from scripts others have done;
Code: Select all
$jobName = Read-Host "Enter Veeam Job Name"
$vmName = Read-Host "Enter VM Name"
# Find the job that has our VM
$job = Get-VBRJob | where {$_.Name -eq $jobName}
# Strip the prefix and get all objects from vcenter apart from our target VM
$jobName = $jobName.Substring(4)
$Objects = Get-Folder | where {$_.type -eq "VM" -and $_.Name -eq $JobName} | Get-VM | where {$_.Name -ne $vmName} | foreach{$_.name}
foreach ($_ in $Objects)
{
Add-VBRViJobObject -Job $job -Entities (Find-VBRViEntity -Name $_)
Get-VBRJobObject -Job $job -Name $_ | Remove-VBRJobObject
}
# 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(*Note: this tells VBR to include them again
foreach ($obj in $incObjs) {
$obj.Delete() | Out-Null
}
-
- Product Manager
- Posts: 20677
- Liked: 2382 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Add VM's to Exclusions list
I've renamed the corresponding topic already for the convenience of future readers. Thanks for pointing that out and for sharing the script, as well.
-
- VP, Product Management
- Posts: 7204
- Liked: 1547 times
- Joined: May 04, 2011 8:36 am
- Full Name: Andreas Neufert
- Location: Germany
- Contact:
Re: Add VM's to Exclusions list
Saw your post while searching for excludes and want to share that in v8 there will be a "Quick Backup" feature. This workaround is then no longer needed.My end goal is to create a PS script that excludes all the vm's in a folder but the one I want to make a quick backup of.
You can start a Quick Backup from a VM. It will detect the job with the last restore point and process an VM only Change Block Tracking based incremental. It is placed next to the restore point of the normal job.
The good thing here is that this restore point do not count as a seperate restore point in the standard Job restore point chain. It will be automatically deleted when the connected (last) restore point will be deleted from standard restore point chain.
It can be also included in the vSphere Web Client to get rid of "Admins doing Snapshots and forget them" when they want to save a restore point before doing changes.
-
- Veeam Software
- Posts: 1838
- Liked: 661 times
- Joined: Mar 02, 2012 1:40 pm
- Full Name: Timothy Dewin
- Contact:
Re: Add VM's to Exclusions list
For a fellow colleague, but based on Tom example, instead of using a VM, here is an example with a tag (tag is matched with regex, vcenter location is wildcard)
Code: Select all
asnp veeampssnapin
$tag = (Find-VBRViEntity -Tags | ? { $_.Path -match "[^\\]*\\Backup Job\\ActiveDirectory$" })
$job = Get-VBRJob -name "Backup Job Demo"
Add-VBRViJobObject -Job $job -Entities $tag
get-vbrjobobject -job $job | ? { $_.Location -eq $tag.Path } | Remove-VBRJobObject
-
- Service Provider
- Posts: 44
- Liked: 4 times
- Joined: Mar 10, 2015 6:16 pm
- Full Name: Mark Hensler
- Contact:
Re: Add VM's to Exclusions list
Not a lot of examples for excluding via tag in powershell. So, I very much appreciated @tdewein's post.
After v9.5U3, you may get the following error:
This is noted in the HelpCenter documentation for Add-VBRViJobObject. The "fix" is to add "-Force".
The resulting code would resemble:
After v9.5U3, you may get the following error:
Code: Select all
Add-VBRViJobObject : Unable to perform data sovereignty compliance check: failed to retrieve location tag.
The resulting code would resemble:
Code: Select all
asnp veeampssnapin
$tag = (Find-VBRViEntity -Tags | ? { $_.Path -match "[^\\]*\\Backup Job\\ActiveDirectory$" })
$job = Get-VBRJob -name "Backup Job Demo"
Add-VBRViJobObject -Job $job -Entities $tag -Force
get-vbrjobobject -job $job | ? { $_.Location -eq $tag.Path } | Remove-VBRJobObject
-
- Influencer
- Posts: 22
- Liked: never
- Joined: Oct 23, 2018 9:02 pm
- Contact:
Re: Add VM's to Exclusions list
Sorry, I know this thread is old, but someone had found this for me and thought it would help. I'd like to use this, but don't fully understand where to put this in a script that uses a csv file to get the VM names. I'm using a csv and importing it because the VM's change from time to time and it's a lot easier than changing the script manually.tsightler wrote: ↑Apr 25, 2014 9:24 pm I know it's a little counter intuitive, but you have to add the object to the job via Powershell before you can use the Remove-VBRJobObject cmdlet to exclude it. Very simple example:So you'd want to have code that enumerates the VMs in the folder, runs through adding them individually to the job, then immediately using Remove-VBRJobObject to explicitly exclude them from the job.Code: Select all
asnp "VeeamPSSnapIn" -ErrorAction SilentlyContinue $jobname = "<Job_Name>" $vmname = "<VM_Name>" Add-VBRViJobObject -Job $jobname -Entities (Find-VBRViEntity -Name $vmname) Get-VBRJobObject -Job $jobname -Name $vmname | Remove-VBRJobObject
The beginning of my script has this:
Code: Select all
Add-PSSnapin VeeamPSSnapIn
Connect-VBRServer -Server intopp-vbkup.beaeng.mfeeng.org
$VMNames = Import-csv -Path "D:\BackupScript\MyVMBackup.csv"
$vmname = "VMIwanttoexclude"
Other stuff like directory to backup to, compression level, etc...
Then this stuff:
Asnp VeeamPSSnapin
$mbody = @()
$VMName = ""
foreach ($VMName in $VMNames)
{
$VM = Find-VBRViEntity -Name $VMName
$ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention
If ($EnableNotification)
{
$TaskSessions = $ZIPSession.GetTaskSessions()
$FailedSessions = $TaskSessions | where {$_.status -eq "EWarning" -or $_.Status -eq "EFailed"}
if ($FailedSessions -ne $Null)
{
$mbody = $mbody + ($ZIPSession | Select-Object @{n="Name";e={($_.name).Substring(0, $_.name.LastIndexOf("("))}} ,@{n="Start Time";e={$_.CreationTime}},@{n="End Time";e={$_.EndTime}},Result,@{n="Details";e={$FailedSessions.Title}})
}
Else
{
$mbody = $mbody + ($ZIPSession | Select-Object @{n="Name";e={($_.name).Substring(0, $_.name.LastIndexOf("("))}} ,@{n="Start Time";e={$_.CreationTime}},@{n="End Time";e={$_.EndTime}},Result,@{n="Details";e={($TaskSessions | sort creationtime -Descending | select -first 1).Title}})
}
}
}
If ($EnableNotification)
{
Send-MailMessage -From $EmailFrom -To $EmailTo -Cc $EmailCC -Subject $EmailSubject -Body ($mbody | Out-String) -Priority $priority -SmtpServer $smtpServer
}
-
- Product Manager
- Posts: 20677
- Liked: 2382 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Add VM's to Exclusions list
The provided script executes VeeamZIP session. VeeamZIP doesn't have any exclusions. Thanks!
-
- Enthusiast
- Posts: 32
- Liked: 6 times
- Joined: Apr 05, 2023 1:06 pm
- Full Name: maanlicht
- Contact:
Re: Add VM's to Exclusions list
The solutions mentioned above has always worked for me in the past. However Since v12 things changed for copyjobs. In v11 we could use this trick for copy jobs as the jobs supported individual VMs. In v12 however copyjobs only support 'Jobs' or 'repositories'.
Trough PowerShell however we can still add individual VMs to backupcopy jobs as mentioned above. However if we do the job can no longer be edited as we receive the error "Guid should contain 32 digits with 4 dashes". (Smells like we need some data validation in the PS command?)
Interestingly I am able to get the job working again with the 'Remove-VBRJobObject' command where it moves the VM to the exclusion list as we originally intended. I can edit the job once more. I though I was out of the woods but not yet, once I run the backupcopy job it doesnt honor the exclusion and still processes the VM. Its only after I make a manual modification to the exclusion list trough the gui that the exclusion is honored. Its a manual workaround but not good for automation.
Does v12 have any other way of excluding VMs in powershell?
Trough PowerShell however we can still add individual VMs to backupcopy jobs as mentioned above. However if we do the job can no longer be edited as we receive the error "Guid should contain 32 digits with 4 dashes". (Smells like we need some data validation in the PS command?)
Interestingly I am able to get the job working again with the 'Remove-VBRJobObject' command where it moves the VM to the exclusion list as we originally intended. I can edit the job once more. I though I was out of the woods but not yet, once I run the backupcopy job it doesnt honor the exclusion and still processes the VM. Its only after I make a manual modification to the exclusion list trough the gui that the exclusion is honored. Its a manual workaround but not good for automation.
Does v12 have any other way of excluding VMs in powershell?
-
- Veeam Software
- Posts: 2607
- Liked: 610 times
- Joined: Jun 28, 2016 12:12 pm
- Contact:
Re: Add VM's to Exclusions list
Hi @maanlicht,
Regrettably, I'm not sure this is exposed on v12 at this time. While there are some deep unsupported methods I've experimented with in the past on setting this manually, they were not stable for even lab testing, so I don't recommend trying to do it for production right now.
Unless my colleagues know of a "safe" unsupported method, I think let's consider this a feature request for future releases, as it's a good one.
Regrettably, I'm not sure this is exposed on v12 at this time. While there are some deep unsupported methods I've experimented with in the past on setting this manually, they were not stable for even lab testing, so I don't recommend trying to do it for production right now.
Unless my colleagues know of a "safe" unsupported method, I think let's consider this a feature request for future releases, as it's a good one.
David Domask | Product Management: Principal Analyst
Who is online
Users browsing this forum: Semrush [Bot] and 20 guests