PowerShell script exchange
Post Reply
jayh
Lurker
Posts: 2
Liked: never
Joined: Jul 04, 2011 2:03 pm
Full Name: Jay H
Contact:

Exclude Tags From Backup Job

Post by jayh »

Hi there,

I'm creating a set of backup jobs by Tags, and want to create a catchall job. To do this in the GUI, I'd simply add the VI Cluster (or datacenter) and exclude backup tags. I can create the job, but can't see how to exclude tage from it... how can this be achieved with PowerShell?

TIA

david.domask
Veeam Software
Posts: 498
Liked: 134 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Exclude Tags From Backup Job

Post by david.domask » 1 person likes this post

Hi Jay,

The way to do this is a bit "backwards" but it's because you have to rely on Remove-VBRJobObject to do it: https://helpcenter.veeam.com/docs/backu ... ml?ver=110.

Basically, whatever you pass to this when you _DON'T_ uses the -Completely parameter gets flipped from an Include to an Exclude Object, but you cannot pass an object to it directly, it needs to be in the job. So it's kind of a bit funny that you have to add the object first and then exclude it.

Thus, your workflow will be like:

Code: Select all

$job = Get-VBRJob -Name 'name of job'
$tag = Find-VBRViEntity -Tags -name 'name of tag'   #https://helpcenter.veeam.com/docs/backup/powershell/find-vbrvientity.html?ver=110#examples
Add-VBRViJobObject -Job $job -Entities $tag -Force #add force to avoid Location mismatch issues just in case
$job = Get-VBRJob -Name 'name of job' #we call it again to get the fresh state with the added tag
$Obj = Get-VBRJobObject -Job $job
$tagObj = $Obj | Where-Object {$_.Name -eq 'tag name'}
Remove-VBRJobObject -Objects $tagObj
It's a bit cumbersome so probably write some function to automate a lot of that, maybe accepting the Tag Name and Job Name and then handling the rest.

Edit: I do want to note that I seem to recall some tag stuff required v11a cumulative patches, but I can't find the reference; so best to be on fully patched v11a.
David Domask | Director: Customer Care | Veeam Technical Support

jayh
Lurker
Posts: 2
Liked: never
Joined: Jul 04, 2011 2:03 pm
Full Name: Jay H
Contact:

Re: Exclude Tags From Backup Job

Post by jayh »

Thanks David, I did eventually figure that out... less than intuative though... as you say, a bit backwards

Much appreciated :)

david.domask
Veeam Software
Posts: 498
Liked: 134 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Exclude Tags From Backup Job

Post by david.domask »

Glad you figured it out and glad I could confirm! I have noted an internal request on this as with unsupported .NET methods it is possible an Exclude-Type object directly, so in theory it's possible; I noticed some irregularities with console performance afterwards so I'm not going to post the code here as likely it's not 100% safe (just a guess, but prolly it messes up some linking in the DB and makes it slow), but for me says it should be doable, and hopefully can be done in the future :)
David Domask | Director: Customer Care | Veeam Technical Support

pirx
Veeam Legend
Posts: 437
Liked: 52 times
Joined: Dec 20, 2015 6:24 pm
Contact:

Re: Exclude Tags From Backup Job

Post by pirx »

Same task here, trying to exclude VMs with a tag that is set during installation. We have a tag category OperationalState with a tag like "Installation". Find-VBRViEntity seems only to look for a tag, can I also limit to a category? Not sure if it can happen that tag "Installation" is used in different categories, but I'd like to have it distinct.

Code: Select all

Type        : Tag
Reference   : urn:vmomi:InventoryServiceTag:4cb4be3c-8867-4c60-98a4-d0590d2cedd8:GLOBAL
TagQsId     : urn:vmomi:InventoryServiceTag:4cb4be3c-8867-4c60-98a4-d0590d2cedd8:GLOBAL
Id          : 02fdb43d-1cd1-4665-9a59-f5dc21765bec_urn:vmomi:InventoryServiceTag:4cb4be3c-8867-4c60-98a4-d0590d2cedd8:GLOBAL
Name        : Installation
Path        : xxxx\OperationalState\Installation

pirx
Veeam Legend
Posts: 437
Liked: 52 times
Joined: Dec 20, 2015 6:24 pm
Contact:

Re: Exclude Tags From Backup Job

Post by pirx »

ah, this seems to be working

Code: Select all

Find-VBRViEntity -Tags -Name 'Installation' | where Path -EQ 'xxxxx\OperationalState\Installation'

Code: Select all

ConnHostId  : 02fdb43d-1cd1-4665-9a59-f5dc21765bec
Type        : Tag
Reference   : urn:vmomi:InventoryServiceTag:4cb4be3c-8867-4c60-98a4-d0590d2cedd8:GLOBAL
TagQsId     : urn:vmomi:InventoryServiceTag:4cb4be3c-8867-4c60-98a4-d0590d2cedd8:GLOBAL
Id          : 02fdb43d-1cd1-4665-9a59-f5dc21765bec_urn:vmomi:InventoryServiceTag:4cb4be3c-8867-4c60-98a4-d0590d2cedd8:GLOBAL
Name        : Installation
Path        : xxxxxx\OperationalState\Installation
Description : not fully working. Installation process running.

pirx
Veeam Legend
Posts: 437
Liked: 52 times
Joined: Dec 20, 2015 6:24 pm
Contact:

Re: Exclude Tags From Backup Job

Post by pirx »

One addition: I've to used -Location to exclude the tag

But this seems a bit dangerous. To first include it and then exclude it. This should be run on a daily base and the tag added to excludes in all jobs. If something goes wrong, then the result will be the opposite of an exclude.

Code: Select all

$jobname = 'myJob'
$job = Get-VBRJob -Name '$jobname'
$tag = Find-VBRViEntity -Tags -Name 'Installation' | where Path -EQ 'myvCenter\OperationalState\Installation'    #https://helpcenter.veeam.com/docs/backup/powershell/find-vbrvientity.html?ver=110#examples
Add-VBRViJobObject -Job $jobname -Entities $tag -Force #add force to avoid Location mismatch issues just in case

$job = Get-VBRJob -Name '$jobname' #we call it again to get the fresh state with the added tag
$Obj = Get-VBRJobObject -Job $jobname
$tagObj = $Obj | Where-Object {$_.Location -eq 'myvCenter\OperationalState\Installation'}
Remove-VBRJobObject -Objects $tagObj

david.domask
Veeam Software
Posts: 498
Liked: 134 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Exclude Tags From Backup Job

Post by david.domask »

Hi @pirx,

Glad you were able to figure it out.

With regards to your statement, I can understand the concern I suppose; I would advise a few things I guess:

1. Add logic to the script with a try/catch and for the catch, disable the job and send a warning with Send-MailMesssage to the backup administrators to check the job
2. Add logging to the script to follow what broke, so it's faster and easier to catch what might have gone wrong.
3. Add a check after the script runs once more to parse the JobObjects and check the Included objects for the undesired elements, and then run the same disable/send email function if they are detected as an Include.

I'm not so sure this code block has a lot to get wrong, but I understand your concerns.

(Also, I'm assuming maybe this is just pseudo-code, but remember to double-quote "" to use shell expansions for your variables :) I'm sure you know it, just making sure that the above is only pseudocode)
David Domask | Director: Customer Care | Veeam Technical Support

Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests