PowerShell script exchange
Post Reply
chris.childerhose
Veeam Vanguard
Posts: 572
Liked: 132 times
Joined: Aug 13, 2014 6:03 pm
Full Name: Chris Childerhose
Location: Toronto, ON
Contact:

Filter Jobs by # of Objects

Post by chris.childerhose »

I have upgraded to Veeam 9 and now need to run Active Full backups for the Per-VM settings in my repositories. I want to do this via Powershell but want to filter the jobs based on Object count.

So anything greater than 1 (multiple VMs in a job) and then run Full Backup to create the new per VM VBK files. I am doing this manually now but a script would be better.

Anyone have an idea? I just need to know mainly the variable for Object.
-----------------------
Chris Childerhose
Veeam Vanguard / Veeam Legend / Veeam Ceritified Architect / VMCE
vExpert / VCAP-DCA / VCP8 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose
nefes
Veeam Software
Posts: 643
Liked: 162 times
Joined: Dec 10, 2012 8:44 am
Full Name: Nikita Efes
Contact:

Re: Filter Jobs by # of Objects

Post by nefes »

You can use Get-VBRJobObject to find objects in job.
Also make sure you don't just check the number of objects, if you use containers (so jobs with 1 host certainly do require enabling this option, while job with 1 vm does not).
chris.childerhose
Veeam Vanguard
Posts: 572
Liked: 132 times
Joined: Aug 13, 2014 6:03 pm
Full Name: Chris Childerhose
Location: Toronto, ON
Contact:

Re: Filter Jobs by # of Objects

Post by chris.childerhose »

Thanks. So how would you filter by jobs that have more than 1 object (>1)?
-----------------------
Chris Childerhose
Veeam Vanguard / Veeam Legend / Veeam Ceritified Architect / VMCE
vExpert / VCAP-DCA / VCP8 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose
nefes
Veeam Software
Posts: 643
Liked: 162 times
Joined: Dec 10, 2012 8:44 am
Full Name: Nikita Efes
Contact:

Re: Filter Jobs by # of Objects

Post by nefes »

I suppose, that you can skip all jobs, where number of objects is 1 and $object.Object.type property is "VM".
chris.childerhose
Veeam Vanguard
Posts: 572
Liked: 132 times
Joined: Aug 13, 2014 6:03 pm
Full Name: Chris Childerhose
Location: Toronto, ON
Contact:

Re: Filter Jobs by # of Objects

Post by chris.childerhose »

Yes that would work. So what is the variable for Objects? So that I can say either -ne 1 and skip.
-----------------------
Chris Childerhose
Veeam Vanguard / Veeam Legend / Veeam Ceritified Architect / VMCE
vExpert / VCAP-DCA / VCP8 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose
nefes
Veeam Software
Posts: 643
Liked: 162 times
Joined: Dec 10, 2012 8:44 am
Full Name: Nikita Efes
Contact:

Re: Filter Jobs by # of Objects

Post by nefes »

As I said, it can be obtained from Get-VBRJobObject command, like:

Code: Select all

$jobs = Get-VBRJob
foreach ($job in $jobs)
{
  $Object = Get-VBRJobObject -Job $job
  if (($Object.length -eq 1) -and ($Object.Object.Type -eq "VM")) { #skip this job, it contains 1 VM}
  else {#run active full}
}
//fixed couple missprints
veremin
Product Manager
Posts: 20283
Liked: 2257 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Filter Jobs by # of Objects

Post by veremin »

Just want to double-check whether you're aware that per-vm chain is the setting of a backup repository, not of a backup job. So, each job pointed to the repository with per-VM chain enabled will be using this setting, and you cannot filter our one job or another.

So, wouldn't it be easier just assign to a variable names of repositories the said setting should be enabled on, and then enable the said check-box.

Thanks.
chris.childerhose
Veeam Vanguard
Posts: 572
Liked: 132 times
Joined: Aug 13, 2014 6:03 pm
Full Name: Chris Childerhose
Location: Toronto, ON
Contact:

Re: Filter Jobs by # of Objects

Post by chris.childerhose »

v.Eremin wrote:Just want to double-check whether you're aware that per-vm chain is the setting of a backup repository, not of a backup job. So, each job pointed to the repository with per-VM chain enabled will be using this setting, and you cannot filter our one job or another.

So, wouldn't it be easier just assign to a variable names of repositories the said setting should be enabled on, and then enable the said check-box.

Thanks.
Yes I am aware of that but just needed something to run the Active Full jobs since you need to do this once the Per-VM is turned on. :)
-----------------------
Chris Childerhose
Veeam Vanguard / Veeam Legend / Veeam Ceritified Architect / VMCE
vExpert / VCAP-DCA / VCP8 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose
veremin
Product Manager
Posts: 20283
Liked: 2257 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Filter Jobs by # of Objects

Post by veremin »

Is it only one repository? If so, use the following script, it should initiate a full backup cycle for every backup job pointed to repository with predefined name.

Code: Select all

asnp VeeamPSSNapin
foreach ($Job in (Get-VBRJob | where {$_.JobType -eq "Backup" -and $_.FindTargetRepository().name -eq "Name of your Repository"}))
{
$Job | Start-VBRJob -FullBackup
}
Thanks.
chris.childerhose
Veeam Vanguard
Posts: 572
Liked: 132 times
Joined: Aug 13, 2014 6:03 pm
Full Name: Chris Childerhose
Location: Toronto, ON
Contact:

Re: Filter Jobs by # of Objects

Post by chris.childerhose »

Thanks for that as it seems much simpler. For the name of the repository can I string together multiples with commas? Like - $_.FindTargetRepository().name -eq "RepoA,RepoB,RepoC"}
-----------------------
Chris Childerhose
Veeam Vanguard / Veeam Legend / Veeam Ceritified Architect / VMCE
vExpert / VCAP-DCA / VCP8 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose
veremin
Product Manager
Posts: 20283
Liked: 2257 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Filter Jobs by # of Objects

Post by veremin »

Updated version where you can specify names of multiple repositories. Also, this script filters out jobs having only one source object:

Code: Select all

asnp VeeamPSSNapin
$RepositoryList = "Name of first Repository", "Name of second Repository"
foreach ($Repository in (Get-VBRBackupRepository -Name $RepositoryList))
{
foreach ($Job in (Get-VBRJob | where {$_.JobType -eq "Backup" -and $_.FindTargetRepository().name -eq $Repository.name -and $_.GetObjectsInJob().count -gt 1}))
{
$Job | Start-VBRJob -FullBackup
}
}
chris.childerhose
Veeam Vanguard
Posts: 572
Liked: 132 times
Joined: Aug 13, 2014 6:03 pm
Full Name: Chris Childerhose
Location: Toronto, ON
Contact:

Re: Filter Jobs by # of Objects

Post by chris.childerhose »

Thanks allot for this. Maybe we can make this a sticky like the one to turn on BitLooker to make things easier for users to run a Full Backup to take advantage of Per-VM Repository settings. I know the scheduled Full does not do it or until a patch comes out. :D
-----------------------
Chris Childerhose
Veeam Vanguard / Veeam Legend / Veeam Ceritified Architect / VMCE
vExpert / VCAP-DCA / VCP8 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose
veremin
Product Manager
Posts: 20283
Liked: 2257 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Filter Jobs by # of Objects

Post by veremin »

I'm already thinking about that. I might add several lines to it, so that, it gets list of repositories with per-VM chain enabled automatically, instead of waiting for it to be filled manually. Thanks.
veremin
Product Manager
Posts: 20283
Liked: 2257 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Filter Jobs by # of Objects

Post by veremin »

Done. Though, I've decided to remove the line filtering jobs with one VM (as I find it rather isolated case). Thanks.
chris.childerhose
Veeam Vanguard
Posts: 572
Liked: 132 times
Joined: Aug 13, 2014 6:03 pm
Full Name: Chris Childerhose
Location: Toronto, ON
Contact:

Re: Filter Jobs by # of Objects

Post by chris.childerhose »

v.Eremin wrote:Done. Though, I've decided to remove the line filtering jobs with one VM (as I find it rather isolated case). Thanks.
Very nice!! Yeah I just didn't want to run Full backup for a 1 VM job as that is a moot point since Per-VM does not technically apply. Glad to have help create another sticky. 8)
-----------------------
Chris Childerhose
Veeam Vanguard / Veeam Legend / Veeam Ceritified Architect / VMCE
vExpert / VCAP-DCA / VCP8 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests