PowerShell script exchange
Post Reply
siranee.ja
Enthusiast
Posts: 31
Liked: 5 times
Joined: Mar 11, 2019 1:13 am
Contact:

How can I get the history data for Backup Copy Job?

Post by siranee.ja »

Hi Everyone,

I use VBR version 12.1.1.56
How can I get the history data for Backup Copy Job?
I can see all history data from history view of the VBR console.

This snippet get only last session of the job.
$job = Get-VBRJob -Name "Backup Copy Job 1"
$session = Get-VBRSession -Job $job


I want to get the previous data of this Backup Copy Job including specific date time to get them.

Best Regards,
Siranee Jaraswachirakul
david.domask
Veeam Software
Posts: 3227
Liked: 751 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: How can I get the history data for Backup Copy Job?

Post by david.domask »

Hi Siranee,

v12 (and currently in v13) we still have some work to do with Backup Copy and the session reporting due to some differences in how Immediate Copy sessions are handled internally.

For now, please do the following; understand that Backup Copies are a parent job that has worker jobs underneath for each machine in the Backup Copy job. Assume there was only one machine in a Backup Copy Job for example:

Code: Select all

$bcJob = Get-VBRBackupCopyJob
$convJob = Get-VBRJob | Where-Object {$_.Id -eq $bcJob.id}
$workerJobs = $convJob.GetWorkerJobs()
[Veeam.Backup.Core.CBackupSession]::GetByJob($workerJobs[0].id)
Fetch it that way. If you need to report on multiple machines, loop over the $workerJobs array and pull the data out you need.
David Domask | Product Management: Principal Analyst
siranee.ja
Enthusiast
Posts: 31
Liked: 5 times
Joined: Mar 11, 2019 1:13 am
Contact:

Re: How can I get the history data for Backup Copy Job?

Post by siranee.ja »

Hi David,
Thank you for your fast reply.
After I tested run the result below:

[Veeam.Backup.Core.CBackupSession]::GetByJob($workerJobs[0])
Cannot convert argument "jobId", with value: "Veeam.Backup.Core.CBackupJob", for
"GetByJob" to type "System.Guid": "Cannot convert the "Veeam.Backup.Core.CBackupJob"
value of type "Veeam.Backup.Core.CBackupJob" to type "System.Guid"."
At line:4 char:1
+ [Veeam.Backup.Core.CBackupSession]::GetByJob($workerJobs[0])
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument

Best Regards,
david.domask
Veeam Software
Posts: 3227
Liked: 751 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: How can I get the history data for Backup Copy Job?

Post by david.domask »

Ah, apologies, I had a typo (fixed now)

[Veeam.Backup.Core.CBackupSession]::GetByJob($workerJobs[0].id)

GetByJob() method accepts a GUID as argument, I forgot to include the call for id
David Domask | Product Management: Principal Analyst
siranee.ja
Enthusiast
Posts: 31
Liked: 5 times
Joined: Mar 11, 2019 1:13 am
Contact:

Re: How can I get the history data for Backup Copy Job?

Post by siranee.ja »

Hi David,
Thank you for the code.
If I want more detail about the worker job, what should I do?

$backup_start_beg="01/14/2026 00:00 AM";
$backup_start_end="01/15/2026 00:00 AM";
$bcJob = Get-VBRBackupCopyJob -Name "Backup Copy all to veeamrepo_nas"
$convJob = Get-VBRJob | Where-Object {($_.Id -eq $bcJob.id)}
$workerJobs = $convJob.GetWorkerJobs()
[Veeam.Backup.Core.CBackupSession]::GetByJob($workerJobs[0].Id)| Where {($_.CreationTime -gt "$backup_start_beg" -and $_.CreationTime -lt "$backup_start_end")}

The result of the script above:
Job Name State Start Time End Time Result
-------- ----- ---------- -------- ------
Backup Copy all t... Stopped 1/14/2026 8:10:05 AM 1/14/2026 8:18:39 AM Success

I want to get more detail such as transfer bytes , etc.
Best Regards,
siranee.ja
Enthusiast
Posts: 31
Liked: 5 times
Joined: Mar 11, 2019 1:13 am
Contact:

Re: How can I get the history data for Backup Copy Job?

Post by siranee.ja »

Hi David,

I think the answer for my question is below.
$backup_start_beg="01/14/2026 00:00 AM";
$backup_start_end="01/15/2026 00:00 AM";
$bcJob = Get-VBRBackupCopyJob -Name "Backup Copy all to veeamrepo_nas"
$convJob = Get-VBRJob | Where-Object {($_.Id -eq $bcJob.id)}
$workerJobs = $convJob.GetWorkerJobs()
$session=[Veeam.Backup.Core.CBackupSession]::GetByJob($workerJobs[0].Id)| Where {($_.CreationTime -gt "$backup_start_beg" -and $_.CreationTime -lt "$backup_start_end")}
echo $session.info

But I still have question. This jobs have more than one vm to do. If some vm failed and some vm success or the job has warning, Should it show on the $session.info or how can I get the detail of each vm?

Best Regards,
Post Reply

Who is online

Users browsing this forum: No registered users and 430 guests