-
- Influencer
- Posts: 17
- Liked: 1 time
- Joined: Nov 10, 2016 9:58 pm
- Full Name: Craig Connoll
- Contact:
Add TAGS to Objects to exclude
Hi All,
I'm hoping someone can help.
I've tried searching the forums and using code out there, but i'm just not getting anywhere.
I have Backup Copy Jobs that I need to add Exclusions too.
These Exclusions must be a combination of TAGS and DataCenters.
It is easy to do this via the GUI, but when I have loads of Jobs and multiple backup servers to manage, it gets a bit long in the tooth.
I have been able to get the Backup Copy Jobs configured with powershell and this is the only setting i'm struggling with.
Any help will be much appreciated.
I'm hoping someone can help.
I've tried searching the forums and using code out there, but i'm just not getting anywhere.
I have Backup Copy Jobs that I need to add Exclusions too.
These Exclusions must be a combination of TAGS and DataCenters.
It is easy to do this via the GUI, but when I have loads of Jobs and multiple backup servers to manage, it gets a bit long in the tooth.
I have been able to get the Backup Copy Jobs configured with powershell and this is the only setting i'm struggling with.
Any help will be much appreciated.
-
- Veeam Vanguard
- Posts: 282
- Liked: 113 times
- Joined: Apr 20, 2017 4:19 pm
- Full Name: Joe Houghes
- Location: Castle Rock, CO
- Contact:
Re: Add TAGS to Objects to exclude
Took me a few minutes to run through the overload definitions to create this, but here it is with an example from my lab.
First, create the variables for the empty properties and the 'Exclude' type required by the Update method of the [Veeam.Backup.Core.CObjectInJob] object:
Here's my job before adding the 'VeeamReplication' tag object:
Next, I run the code to add the new 'VeeamReplication' tag and look at the job objects, to verify it is the default 'Include' type.
Lastly, I capture the object to be set to an 'Exclude' type, run the Update method of the job object, and here is the final result of the job objects:
This should help you to set your exclusions. You'll need to run this once per job object (for each object in the job to be excluded) to flip it to an 'exclude' type.
You may want to create a collection of your servers, jobs and tags to be excluded, then you'd only have to loop through it once to run the Update method per object in your collection.
First, create the variables for the empty properties and the 'Exclude' type required by the Update method of the [Veeam.Backup.Core.CObjectInJob] object:
Code: Select all
$vss = [Veeam.Backup.Model.CGuestProcessingOptions]::CreateDefaultForObject($false)
$diskfilter = [Veeam.Backup.Model.CDiskFilterInfo]::CreateEmpty
$exclusion = [Veeam.Backup.Model.CDbObjectInJobInfo+EType]::Exclude
Here's my job before adding the 'VeeamReplication' tag object:
Code: Select all
$job | Get-VBRJobObject
Name Type ApproxSize Location
---- ---- ---------- --------
VeeamTagTest Include 142.4 GB ausvcenter.lab.fullstackgeek.net\VeeamBackup (Tags for Backup Jobs)\VeeamTagTest (Job Tag for Veeam Backups)
Next, I run the code to add the new 'VeeamReplication' tag and look at the job objects, to verify it is the default 'Include' type.
Code: Select all
$job = Get-VBRJob -Name 'AUSVCENTER-TagTest'
$tag = Find-VBRViEntity -Name 'VeeamReplication' -Server (Get-VBRServer -Name ausvcenter.lab.fullstackgeek.net) -Tags
Add-VBRViJobObject -Job $job -Entities $tag
$job | Get-VBRJobObject
Name Type ApproxSize Location
---- ---- ---------- --------
VeeamTagTest Include 142.4 GB ausvcenter.lab.fullstackgeek.net\VeeamBackup (Tags for Backup Jobs)\VeeamTagTest (Job Tag for Veeam Backups)
VeeamReplication Include 0.0 B ausvcenter.lab.fullstackgeek.net\VeeamReplication (Tags for Replication Jobs)
Lastly, I capture the object to be set to an 'Exclude' type, run the Update method of the job object, and here is the final result of the job objects:
Code: Select all
$exclude = $job | Get-VBRJobObject -Name 'VeeamReplication'
$exclude.Update($vss,$diskfilter,$true,$exclusion)
$job | Get-VBRJobObject
Name Type ApproxSize Location
---- ---- ---------- --------
VeeamTagTest Include 142.4 GB ausvcenter.lab.fullstackgeek.net\VeeamBackup (Tags for Backup Jobs)\VeeamTagTest (Job Tag for Veeam Backups)
VeeamReplication Exclude 0.0 B ausvcenter.lab.fullstackgeek.net\VeeamReplication (Tags for Replication Jobs)
You may want to create a collection of your servers, jobs and tags to be excluded, then you'd only have to loop through it once to run the Update method per object in your collection.
Husband, Father, Solutions Architect, Geek | @DenverVMUG & @DenverPSUG leader | International Speaker | Veeam Vanguard | vExpert (PRO) | Cisco Champion
-
- Influencer
- Posts: 17
- Liked: 1 time
- Joined: Nov 10, 2016 9:58 pm
- Full Name: Craig Connoll
- Contact:
Re: Add TAGS to Objects to exclude
Hi jhoughes,
Thanks for the Update.
I have tested the code, but i'm getting the following error:
When creating the variable $diskfilter I get the below Error.
The the last error is:
The end result is that the TAGS are added to the "Objects to Process" but not flipped to the exclusions Objects
Thanks for the Update.
I have tested the code, but i'm getting the following error:
When creating the variable $diskfilter I get the below Error.
Code: Select all
Unable to find type [Veeam.Backup.Model.CDiskFilterInfo].
At line:7 char:15
+ $diskfilter = [Veeam.Backup.Model.CDiskFilterInfo]::CreateEmpty
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Veeam.Backup.Model.CDiskFilterInfo:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
Code: Select all
Unable to find type [Veeam.Backup.Model.CDiskFilterInfo].
At line:7 char:15
+ $diskfilter = [Veeam.Backup.Model.CDiskFilterInfo]::CreateEmpty
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Veeam.Backup.Model.CDiskFilterInfo:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
Exception calling "Update" with "4" argument(s): "Object reference not set to an instance of an object."
At line:15 char:1
+ $exclude.Update($vss,$diskfilter,$true,$exclusion)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : NullReferenceException
-
- Veeam Vanguard
- Posts: 282
- Liked: 113 times
- Joined: Apr 20, 2017 4:19 pm
- Full Name: Joe Houghes
- Location: Castle Rock, CO
- Contact:
Re: Add TAGS to Objects to exclude
I should have specified that I'm running U4, although the type name should exist for you.
Either way, I realized this morning that I forgot the easy way to so this. The Remove-VBRJobObject cmdlet will actually set an exclusion if you don't use the -Completely switch parameter.
Just run the code for Add-VBRViJobObject, then get that same object and pipe it to Remove-VBRJobObject. It should set the object as an exclusion.
Apologies if there a typo, typed from cell phone.
Either way, I realized this morning that I forgot the easy way to so this. The Remove-VBRJobObject cmdlet will actually set an exclusion if you don't use the -Completely switch parameter.
Just run the code for Add-VBRViJobObject, then get that same object and pipe it to Remove-VBRJobObject. It should set the object as an exclusion.
Apologies if there a typo, typed from cell phone.
Husband, Father, Solutions Architect, Geek | @DenverVMUG & @DenverPSUG leader | International Speaker | Veeam Vanguard | vExpert (PRO) | Cisco Champion
-
- VP, Product Management
- Posts: 6035
- Liked: 2860 times
- Joined: Jun 05, 2009 12:57 pm
- Full Name: Tom Sightler
- Contact:
Re: Add TAGS to Objects to exclude
Yep, I sometimes joke that this is perhaps the worst named cmdlet in Powershell history, a "remove" cmdlet that, by default, doesn't actually perform a remove of anything, and then requires some fairly strangely named flag to actually remove the object. But it's difficult to fix due to the fact that it's been around a long time and lots of code now depends on the existing behavior.Either way, I realized this morning that I forgot the easy way to so this. The Remove-VBRJobObject cmdlet will actually set an exclusion if you don't use the -Completely switch parameter.
Just run the code for Add-VBRViJobObject, then get that same object and pipe it to Remove-VBRJobObject. It should set the object as an exclusion.
Who is online
Users browsing this forum: No registered users and 10 guests