PowerShell script exchange
Post Reply
tester19
Novice
Posts: 8
Liked: never
Joined: Apr 20, 2023 7:07 pm
Full Name: tester testovac
Contact:

VBR; Agent backups; mixing of policy sessions and actual backup sessions

Post by tester19 »

I will try to simplify to the core.

This is a backup job in VBR. Its a workstation backup managed by an agent.
I would like to know last time it was backed up and if it was successful, using powershell.

The issue is that if we look at history, we see not just backup runs, but also policies updates.
And using now recommended VBRComputerBackupJob and VBRComputerBackupJobSession I seem unable to find a way to distinguish between these two sessions types.
But I need to filter out policy runs as they can be successful while the actual backups of data could be failing.

This is just code I am testing stuff with.

Code: Select all

$AgentJobs = @(Get-VBRComputerBackupJob)
#$AgentJobs

foreach ($Job in $AgentJobs) {

#$job
$Job.Name
$Job.GetType().Name
$Job.Id.Guid

"----------------------"

$JobSessions = @(Get-VBRComputerBackupJobSession | where {$_.JobId -eq $job.Id})

foreach ($session in $JobSessions) {
    $session
}
}
david.domask
Veeam Software
Posts: 1226
Liked: 323 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: VBR; Agent backups; mixing of policy sessions and actual backup sessions

Post by david.domask »

Hi @tester19,

Not sure I'm following. If I run simple Get-VBRComputerBackupJob | Get-VBRComputerBackupJobSession, I just get the job runs.

Can you show some example data where you're getting wrong results?
David Domask | Product Management: Principal Analyst
tester19
Novice
Posts: 8
Liked: never
Joined: Apr 20, 2023 7:07 pm
Full Name: tester testovac
Contact:

Re: VBR; Agent backups; mixing of policy sessions and actual backup sessions

Post by tester19 »

tester19
Novice
Posts: 8
Liked: never
Joined: Apr 20, 2023 7:07 pm
Full Name: tester testovac
Contact:

Re: VBR; Agent backups; mixing of policy sessions and actual backup sessions

Post by tester19 »

I read up on backup policies cuz I had some misconception about them. Helped a lot to understand when they should be used and why.

I installed v12 on my test machine. It fixed some issues I had with Get-VBRComputerBackupJob or Get-VBRComputerBackupJobSession returning not an array list but object that had hard time filtering.

I then decided to use Get-VBRBackup as the source of the info for the last job done and seems to work decently, but its just rough proof of concept.

Code: Select all

$AgentJobsAndPolicies = Get-VBRComputerBackupJob | Sort-Object typetostring, name

# FOR EVERY JOB GATHER BASIC INFO
foreach ($Job in $AgentJobsAndPolicies) {

    $Job.Name
    $Job.Type
    $Job.Mode

    $Job.Id
    $JobNameWithAsterisk = '{0}*' -f $Job.Name
    $winbackup = Get-VBRBackup -Name $JobNameWithAsterisk
        
    $restorepoints = Get-VBRRestorePoint -Backup $winbackup | Sort-Object CreationTime -Descending
    foreach ($r in $restorepoints) {
        $r.CreationTime.DateTime
        "-0------------------------------"
    }
    "================"
    #$restorepoints[0].CommonInfo
    $LastBackup = $restorepoints[0].CreationTime.DateTime
    $LastBackup
}
tester19
Novice
Posts: 8
Liked: never
Joined: Apr 20, 2023 7:07 pm
Full Name: tester testovac
Contact:

Re: VBR; Agent backups; mixing of policy sessions and actual backup sessions

Post by tester19 »

Reporting that actual solution was posted here

The name of the job in session needs ?* added and then it filters out policies.

Code: Select all

$job = Get-VBRComputerBackupJob -Name 'Agent Backup Job'
$sessions = Get-VBRComputerBackupJobSession -Name "$($job.Name)?*"
foreach ($session in $sessions) {
 Get-VBRTaskSession -Session $session
}
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests