Add VM's to Exclusions list

PowerShell script exchange

Add VM's to Exclusions list

Veeam Logoby PNWMtnBiker » Fri Apr 25, 2014 7:02 pm

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.
PNWMtnBiker
Enthusiast
 
Posts: 63
Liked: 8 times
Joined: Thu Jan 16, 2014 11:12 pm
Full Name: Jon Dufour

Re: Add VM's to Exclusions list

Veeam Logoby tsightler » Fri 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:
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


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.
tsightler
Veeam Software
 
Posts: 4775
Liked: 1742 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: Add VM's to Exclusions list

Veeam Logoby PNWMtnBiker » Fri Apr 25, 2014 11:50 pm

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!
PNWMtnBiker
Enthusiast
 
Posts: 63
Liked: 8 times
Joined: Thu Jan 16, 2014 11:12 pm
Full Name: Jon Dufour

Re: Add VM's to Exclusions list

Veeam Logoby v.Eremin » Mon Apr 28, 2014 7:23 am

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.
v.Eremin
Veeam Software
 
Posts: 13296
Liked: 974 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Add VM's to Exclusions list

Veeam Logoby PNWMtnBiker » Mon Apr 28, 2014 8:17 pm

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;

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
}
PNWMtnBiker
Enthusiast
 
Posts: 63
Liked: 8 times
Joined: Thu Jan 16, 2014 11:12 pm
Full Name: Jon Dufour

Re: Add VM's to Exclusions list

Veeam Logoby v.Eremin » Tue Apr 29, 2014 9:03 am

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.
v.Eremin
Veeam Software
 
Posts: 13296
Liked: 974 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Add VM's to Exclusions list

Veeam Logoby Andreas Neufert » Fri Aug 29, 2014 6:52 am

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.


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.
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.
Andreas Neufert
Veeam Software
 
Posts: 2201
Liked: 360 times
Joined: Wed May 04, 2011 8:36 am
Location: Germany
Full Name: @AndyandtheVMs Veeam PM

Re: Add VM's to Exclusions list

Veeam Logoby tdewin » Wed May 13, 2015 9:57 am

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
tdewin
Veeam Software
 
Posts: 1047
Liked: 361 times
Joined: Fri Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 8 guests