PowerShell script exchange
Post Reply
edirschedl
Enthusiast
Posts: 44
Liked: 4 times
Joined: Jul 21, 2016 12:29 pm
Full Name: Emanuel Dirschedl
Contact:

Get-VBRTaskSession for backup copy jobs

Post by edirschedl »

Hi,

it seems for me, that the Get-VBRTaskSession command isn't working for Backup Copy jobs, right?

Following command I wanted to run (Get-VBRBackupSession alone is working!):

Code: Select all

Get-VBRBackupSession -Name "<Name of Backup Copy Job>" | Get-VBRTaskSession
Is there any other possibility to get the current status (running, failed, successful) of a single vm in a Backup Copy job?

Thank you,
Emanuel
veremin
Product Manager
Posts: 20271
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Get-VBRTaskSession for backup copy jobs

Post by veremin »

The following script works fine me - it returns task sessions for specified backup copy job:

Code: Select all

Asnp VeeamPSSnapin
$Job = Get-VBRJob -name "Backup Copy Job Name"
$Session = $Job.FindLastSession()
$Session | Get-VBRTaskSession
If you want to check the overall job status, you can use this script instead:

Code: Select all

Asnp VeeamPSSnapin
$Job = Get-VBRJob -name "Backup Copy Job Name"
$Job.GetLastState()
Thanks.
tsightler
VP, Product Management
Posts: 6009
Liked: 2843 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Get-VBRTaskSession for backup copy jobs

Post by tsightler »

This is a weird behavior of Get-VBRBackupSession. The '-Name' parameter matches the session name, but the session name in many cases has added text to indicate the run type, for example, if you have a job that is named "MyBackup" but you actually look at the session names you'll see:

MyBackup (Full)
MyBackup (Incremental)

The easy workaround for this is to just use a wildcard character after the job name like this:

Code: Select all

Get-VBRBackupSession -Name "MyBackup*" | Get-VBRTaskSession
Another options is to use a filter:

Code: Select all

Get-VBRBackupSession | ?{$_.JobName -eq "MyBackup"} | Get-VBRTaskSession
Get-VBRBackupSession is quite a heavy command, so if I know I'm going to reference backup sessions a lot in the script I usually just load them up into pre-sorted hash table using either JobName or JobId as the key, for example like so:

Code: Select all

$BackupSessions = Get-VBRBackupSession | Sort JobName, CreationTime | Group-Object -Property JobName -AsHashTable
Then you can reference any backup sessions for any jobs with $BackupSessions.'<Job_Name>' extremely quickly. You could also add a filter to the above code to grab on the most recent X number of days, especially if you have lots of sessions.

If you're just looking for the most recent/currently active session then something like this should work and be very fast:

Code: Select all

Get-VBRJob -Name "<Job_Name>").FindLastSession() | Get-VBRTaskSession
Virtali
Lurker
Posts: 1
Liked: never
Joined: Apr 15, 2019 5:08 pm
Contact:

Re: Get-VBRTaskSession for backup copy jobs

Post by Virtali »

though this is a rather old thread it seems that this issue is still present.
the given code samples provided above do not work.
i.e. : Get-VBRJob -Name "<Job_Name>").FindLastSession() | Get-VBRTaskSession
It works, if Job_Name is a regular backup job, but not for an Agent backup job (.JobType -eq "EpAgentBackup").
Regardless which way I try to get the tasks of an Agent backup job session it returns nothing.

Any ideas, suggestions, ...?

P.S. currently using VBR 11, latest patchlevel
oleg.feoktistov
Veeam Software
Posts: 1912
Liked: 635 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Get-VBRTaskSession for backup copy jobs

Post by oleg.feoktistov »

We now have a cmdlet to get agent backup sessions and Get-VBRTaskSession also accepts input from it:

Code: Select all

$sessions = Get-VBRComputerBackupJobSession
foreach ($session in $sessions) {
  Get-VBRTaskSession -Session $session
}
Hope it helps,
Oleg
Post Reply

Who is online

Users browsing this forum: oscarm and 21 guests