PowerShell script exchange
Post Reply
MaxKozlov
Influencer
Posts: 19
Liked: 5 times
Joined: Oct 26, 2017 12:52 pm
Full Name: Max Kozlov
Contact:

Is there any way to get OIBS for Agent Server job

Post by MaxKozlov »

When I had client side Agent Job this code worked.

but when I created protection group and Server side Agent backup job it just return null

Code: Select all

$agentbackup = # there I get agent backup
$oibs = $agentbackup.GetLastOibs()

#.GetLastPoint() also does not work
How else can I get OIBs for Server Agent jobs ?
jhoughes
Veeam Vanguard
Posts: 279
Liked: 112 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Castle Rock, CO
Contact:

Re: Is there any way to get OIBS for Agent Server job

Post by jhoughes »

I've verified that I can run both of those methods against server managed Agent backups within my lab.

Trimmed to save some space:

Code: Select all

PS C:\Users\svc_veeam_br> $agentbackup = Get-VBRBackup -Name 'VeeamOneAgentTest - ausmembertst97.lab.fullstackgeek.net'

PS C:\Users\svc_veeam_br> $agentbackup.GetLastOibs()

VM Name                   Creation Time          Type
-------                   -------------          ----
ausmembertst97.lab.ful... 8/11/2019 5:37:57 PM   Increment

PS C:\Users\svc_veeam_br> $agentbackup.GetLastPoint()

Info               : Veeam.Backup.Model.CPointInfo
Id                 : 04272d5a-3471-44da-90e1-d94eda055f52
CreationTime       : 8/11/2019 5:37:16 PM
Algorithm          : Increment
Type               : Normal
IsFull             : False
IsIncremental      : True
The backup objects themselves are going to be specific to the endpoint, since they are each a separate chain. You would only get a single endpoint as result within each agent backup, even if it returns multiple restore points, so I'm confused what you are trying to get from the OIBs, unless it's just confirming the VM name.

What code did you run to get the agent backup? Have you already run the server-managed agent job?
Husband, Father, Solutions Architect, Geek Extraordinaire | @DenverVMUG, @AustinVMUG & @ATXPowerShell leader | VMware vExpert | Cisco Champion
Egor Yakovlev
Veeam Software
Posts: 2537
Liked: 683 times
Joined: Jun 14, 2013 9:30 am
Full Name: Egor Yakovlev
Location: Prague, Czech Republic
Contact:

Re: Is there any way to get OIBS for Agent Server job

Post by Egor Yakovlev » 1 person likes this post

Greetings, Max!

I guess you are trying to retrieve IDs of servers protected by last job run?
Try this:

Code: Select all

Add-PSSnapin *
Connect-VBRServer -server my.vbr.server

#Get all physical agent jobs
$a = Get-VBRJob | Where-Object {$_.JobType -eq "EpAgentBackup"}

#Find CNOs if those are clusters or standalone
$PhysicalClusterName = $a.GetViOijs()

#Get child job that protects machines
$childJob = $a.GetChildJobs()

#Find last backup for physical backups
$lastBackup = $childJob.GetLastBackup()

#Get Last OIBs :D
$result = $lastBackup.GetLastOibs()
$result | Sort-Object -Property fqdn | Format-Table -Property Fqdn, @{L="OIB ID";E={$_.ID}}, BackupID, CreationTimeUTC
# $PhysicalClusterName contains CNO of your physical cluster, just in case

Hope that helps!
MaxKozlov
Influencer
Posts: 19
Liked: 5 times
Joined: Oct 26, 2017 12:52 pm
Full Name: Max Kozlov
Contact:

Re: Is there any way to get OIBS for Agent Server job

Post by MaxKozlov »

In fact, I need to get a list of the most recent backups stored on the remote and main storage per server, and if it is different, run the copy jobs corresponding to the differences. (each job contains several servers)
Oib contain all needed info for this task

Code: Select all

VM Name              Creation Time          Type
-------                   -------------                 ----
SERVER1                 18.06.2019 12:18:57    Increment
SERVER2                 28.06.2019 13:16:55    Full
And when I has standalone agents it worked. May be because each backup job contain only one agent ?

But for some reason now I can't get oibs like @houghes.

the original code look like this

Code: Select all

$intoibs = @($intBackups.GetLastOibs())
$extoibs = @($extBackups.GetLastOibs())

"There is a $($intBackups.Count)($($intoibs.Count)) Internal and $($extBackups.Count)($($extoibs.Count)) External jobs(backups)"
# there is some difference in backups ?
$toEnable = Compare-Object -ReferenceObject $intoibs -DifferenceObject $extoibs -Property Name, CreationTime, IsConsistent -PassThru |
Where-Object { $_.SideIndicator -eq '<=' } |
ForEach-Object {
	$b = $_.GetBackup()
	$extjobs | Where-Object { $b.JobId -in $_.LinkedJobIds }
} | Sort-Object -Property Name -Unique
$toEnable | Enable-VBRJob
MaxKozlov
Influencer
Posts: 19
Liked: 5 times
Joined: Oct 26, 2017 12:52 pm
Full Name: Max Kozlov
Contact:

Re: Is there any way to get OIBS for Agent Server job

Post by MaxKozlov »

Thanks Egor,

GetChildJobs()/GetLastBackup()/GetLastOibs() chain do what I want

But one last question - If I need to always try to GetChildJobs() or there is some attribute "there is a child jobs presented" ?
Egor Yakovlev
Veeam Software
Posts: 2537
Liked: 683 times
Joined: Jun 14, 2013 9:30 am
Full Name: Egor Yakovlev
Location: Prague, Czech Republic
Contact:

Re: Is there any way to get OIBS for Agent Server job

Post by Egor Yakovlev »

This is valid for all physical agent-based backup jobs managed by Veeam B&R(JobType -eq "EpAgentBackup") - for standalone server backup jobs(manually added by IP to the job), for failover clusters(used Cluster Name Object to add servers to the job) and jobs with a Protection Groups added as a scope. So feel free to use it "by default".
/Cheers!
kalled
Novice
Posts: 4
Liked: never
Joined: Nov 05, 2013 6:11 am
Full Name: Karl D
Contact:

Re: Is there any way to get OIBS for Agent Server job

Post by kalled »

Hello Egor,

this code chain helped me finally to query our Agent Backups in an easy way. A last part I can't find currently - could we query the state of last backup as well? For VMs we have it to check if it is Failed, Warning or Successful. Sth like that for our (few) agent backups would be perfect.

Many thanks
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Is there any way to get OIBS for Agent Server job

Post by oleg.feoktistov »

Hi Karl,

I believe, what you are referring to is agent backup session result, right?
For last agent backup sessions specifically it can be retrieved in the following way:

Code: Select all

PS C:\Users\admin> $agentJobs = Get-VBRJob | where {$_.JobType -eq 'EPAgentBackup'}
PS C:\Users\admin> $agentJobs.FindLastSession()

Job Name             State      Start Time             End Time               Result
--------             -----      ----------             --------               ------
BACKUP-AGENT-01      Stopped    12/9/2019 4:54:14 PM   12/9/2019 4:55:32 PM   Failed


PS C:\Users\oleg.feoktistov>
Thanks,
Oleg
kalled
Novice
Posts: 4
Liked: never
Joined: Nov 05, 2013 6:11 am
Full Name: Karl D
Contact:

Re: Is there any way to get OIBS for Agent Server job

Post by kalled »

Thanks Oleg,

Yes, looking for the Agent Backup session - however we are looking more for the status of each Agent. A common failure is that from a Job with 10 Agents 1 failed. We would like to report the one failing Agent then. I have the feeling this might be more complex - as there is one "protection group" inside the Agent Job which includes all the agents. Still the GUI shows currently the 2 failed agents. And this info we would like to extract through Powershell :)

Thanks for any idea!
Karl
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Is there any way to get OIBS for Agent Server job

Post by oleg.feoktistov »

Hi Karl,

Then, for the latest agent backup session try the code below:

Code: Select all

PS C:\Users\admin> $job = Get-VBRJob | where {$_.JobType -eq 'EPAgentBackup'}
PS C:\Users\admin> $session = $job.FindLastSession()
PS C:\Users\admin> $session.GetChildSessions() | Select-Object JobName, CreationTime, State, Result

JobName                         CreationTime            State  Result
-------                         ------------            -----  ------
BACKUP-AGENT-01 - WinServer-01 12/11/2019 2:32:38 PM Stopped Success
BACKUP-AGENT-01 - WinServer-02 12/11/2019 2:32:38 PM Stopped Success

It will show you the status of each child session.
As a JobName, the name of parent backup session + the name of each protection group member processed in child sessions is reflected.

Best regards,
Oleg
kalled
Novice
Posts: 4
Liked: never
Joined: Nov 05, 2013 6:11 am
Full Name: Karl D
Contact:

Re: Is there any way to get OIBS for Agent Server job

Post by kalled »

Hi Oleg,

Much easier than I expected so far, many thanks :)

We're almost there I think - problem I have now is that the failing jobs last session is the last retry only containing the 2 failed agents. Is there a way to get all sessions (maybe limited to last 3 days or so) which I can loop through to find the correct "Success" state for the 8 working agents?

Once again many thanks for the big help already!
Karl
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Is there any way to get OIBS for Agent Server job

Post by oleg.feoktistov »

Hi Karl,

Since in the current VBR version these cmdlets don't support Veeam Agent jobs managed by Backup server,
I would suggest to query all the child sessions inside all the sessions for the agent job using this method:

Code: Select all

$job = Get-VBRJob | where {$_.JobType -eq 'EPAgentBackup'}
$jobSessions = [Veeam.Backup.Core.CBackupSession]::GetByJob($job.id)
foreach ($jobSession in $jobSessions) {
$jobSession.GetChildSessions() | select JobName, State, EndTime, Result
}
You can then filter the output as you like.

Kind regards,
Oleg
Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests