Filter Jobs by # of Objects

PowerShell script exchange

Filter Jobs by # of Objects

Veeam Logoby chris.childerhose » Thu Jan 28, 2016 4:28 pm

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, VCAP-DCA, VMCE9, VCP, MCITP
chris.childerhose
Enthusiast
 
Posts: 71
Liked: 6 times
Joined: Wed Aug 13, 2014 6:03 pm
Location: Toronto, ON
Full Name: Chris Childerhose

Re: Filter Jobs by # of Objects

Veeam Logoby nefes » Thu Jan 28, 2016 4:43 pm

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).
nefes
Veeam Software
 
Posts: 534
Liked: 125 times
Joined: Mon Dec 10, 2012 8:44 am
Full Name: Nikita Efes

Re: Filter Jobs by # of Objects

Veeam Logoby chris.childerhose » Thu Jan 28, 2016 4:56 pm

Thanks. So how would you filter by jobs that have more than 1 object (>1)?
Chris Childerhose, VCAP-DCA, VMCE9, VCP, MCITP
chris.childerhose
Enthusiast
 
Posts: 71
Liked: 6 times
Joined: Wed Aug 13, 2014 6:03 pm
Location: Toronto, ON
Full Name: Chris Childerhose

Re: Filter Jobs by # of Objects

Veeam Logoby nefes » Thu Jan 28, 2016 5:07 pm

I suppose, that you can skip all jobs, where number of objects is 1 and $object.Object.type property is "VM".
nefes
Veeam Software
 
Posts: 534
Liked: 125 times
Joined: Mon Dec 10, 2012 8:44 am
Full Name: Nikita Efes

Re: Filter Jobs by # of Objects

Veeam Logoby chris.childerhose » Thu Jan 28, 2016 5:12 pm

Yes that would work. So what is the variable for Objects? So that I can say either -ne 1 and skip.
Chris Childerhose, VCAP-DCA, VMCE9, VCP, MCITP
chris.childerhose
Enthusiast
 
Posts: 71
Liked: 6 times
Joined: Wed Aug 13, 2014 6:03 pm
Location: Toronto, ON
Full Name: Chris Childerhose

Re: Filter Jobs by # of Objects

Veeam Logoby nefes » Thu Jan 28, 2016 5:37 pm

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
nefes
Veeam Software
 
Posts: 534
Liked: 125 times
Joined: Mon Dec 10, 2012 8:44 am
Full Name: Nikita Efes

Re: Filter Jobs by # of Objects

Veeam Logoby v.Eremin » Thu Jan 28, 2016 5:38 pm

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

Re: Filter Jobs by # of Objects

Veeam Logoby chris.childerhose » Thu Jan 28, 2016 5:39 pm

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, VCAP-DCA, VMCE9, VCP, MCITP
chris.childerhose
Enthusiast
 
Posts: 71
Liked: 6 times
Joined: Wed Aug 13, 2014 6:03 pm
Location: Toronto, ON
Full Name: Chris Childerhose

Re: Filter Jobs by # of Objects

Veeam Logoby v.Eremin » Thu Jan 28, 2016 5:52 pm

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

Re: Filter Jobs by # of Objects

Veeam Logoby chris.childerhose » Thu Jan 28, 2016 5:56 pm

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, VCAP-DCA, VMCE9, VCP, MCITP
chris.childerhose
Enthusiast
 
Posts: 71
Liked: 6 times
Joined: Wed Aug 13, 2014 6:03 pm
Location: Toronto, ON
Full Name: Chris Childerhose

Re: Filter Jobs by # of Objects

Veeam Logoby v.Eremin » Thu Jan 28, 2016 6:08 pm

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

Re: Filter Jobs by # of Objects

Veeam Logoby chris.childerhose » Thu Jan 28, 2016 7:32 pm

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, VCAP-DCA, VMCE9, VCP, MCITP
chris.childerhose
Enthusiast
 
Posts: 71
Liked: 6 times
Joined: Wed Aug 13, 2014 6:03 pm
Location: Toronto, ON
Full Name: Chris Childerhose

Re: Filter Jobs by # of Objects

Veeam Logoby v.Eremin » Fri Jan 29, 2016 10:55 am

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

Re: Filter Jobs by # of Objects

Veeam Logoby v.Eremin » Fri Jan 29, 2016 1:43 pm

Done. Though, I've decided to remove the line filtering jobs with one VM (as I find it rather isolated case). Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Filter Jobs by # of Objects

Veeam Logoby chris.childerhose » Fri Jan 29, 2016 3:48 pm

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, VCAP-DCA, VMCE9, VCP, MCITP
chris.childerhose
Enthusiast
 
Posts: 71
Liked: 6 times
Joined: Wed Aug 13, 2014 6:03 pm
Location: Toronto, ON
Full Name: Chris Childerhose


Return to PowerShell



Who is online

Users browsing this forum: Google [Bot] and 9 guests