PowerShell script exchange
Post Reply
GregorS
Veeam ProPartner
Posts: 58
Liked: 13 times
Joined: Apr 10, 2013 12:11 pm
Full Name: Gregor Smerke
Location: Ljubljana, SI - Slovenia
Contact:

From Restore Point to Backup Session First Run Start Time

Post by GregorS » 1 person likes this post

Hi PowerShell experts and especially Mr. Feoktistov! :wink:

I'm updating a script of mine that I use to assess restore point sizes. It worked well for v11, but things have changed in v12. My script basically sums up backup sizes for all objects that belong to a restore point = job run. It groups objects in a restore point that belong to a single job run and then it sums up their backup sizes. So, in theory, nothing special. I can easily get restore points:

Code: Select all

Get-VBRJob -Name "A Job Name" | ForEach-Object {$_.FindLastBackup()} | Get-VBRRestorePoint
Then I used to group objects by "CreationTime" and sum up their backup sizes.

Code: Select all

$<RestorePoint>.GetStorage().Stats.BackupSize
It worked well in v11 where this property reflected the original (first run) start time of the job session, meaning the first start and not the last successful retry time. In v12 now every object gets a "real" creation time, meaning if a job retried, the creation time is from the last successful retry. I'm struggling with getting a basis that determines a single job run. I discovered that in v12 a "JobRunId" was added but I'd rather not use this property since I'd like that my script works correctly for v11 and v12. I'd rather use a first job run start time because I also use it in output. Any idea on how to get a first job run start time from every restore point object? I need this for restore points from backup jobs, backup copy jobs and agent backup jobs.

Thanks!
oleg.feoktistov
Veeam Software
Posts: 2021
Liked: 673 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: From Restore Point to Backup Session First Run Start Time

Post by oleg.feoktistov » 2 people like this post

Hi Gregor,

To be precise - do you group objects by CreationTime of a restore point (COib) or a storage (CStorage)?
COib is what you get with Get-VBRRestorePoint and CStorage is what you get with $<RestorePoint>.GetStorage()

Best regards,
Oleg
GregorS
Veeam ProPartner
Posts: 58
Liked: 13 times
Joined: Apr 10, 2013 12:11 pm
Full Name: Gregor Smerke
Location: Ljubljana, SI - Slovenia
Contact:

Re: From Restore Point to Backup Session First Run Start Time

Post by GregorS »

Hi Oleg, thank you for your response. I moved on a little since yesterday. For v11 I group restore points by:

Code: Select all

$<RestorePoint>.GetPoint().CreationTime
This works very well for v11 restore points created by backup jobs and backup copy jobs since it returns a "first job run" creation time.
For v12 backup jobs I figured out I can use:

Code: Select all

(Get-VBRSession -Id $<RestorePoint>.JobRunId).CreationTime
This also returns a "first job run" creation time. Now I'm looking into v12 backup copy jobs. They run worker jobs for each source backup job in parallel. What I can get is a list of all worker backup copy jobs but what I need is the parent backup copy job that started them. I think I discovered a bug:

Code: Select all

Get-VBRSession -Job (Get-VBRJob -Name "A Backup Copy Job")
... returns just the last backup copy job session, I expect it should return all of them. Then I could probably use a creation time from this session object.
I know I'm just tinkering around but you have means to show me the official way.
oleg.feoktistov
Veeam Software
Posts: 2021
Liked: 673 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: From Restore Point to Backup Session First Run Start Time

Post by oleg.feoktistov »

Get-VBRSession with -Job parameter is intended to work like that since the times it was used for tape jobs only. However, you suggested a good point - now that we've broadened its usage, we should allow reflecting all the sessions for the specific job. At the moment, if you want to get all the parent sessions for a particular backup copy job, try this:

Code: Select all

$backupCopy = Get-VBRBackupCopyJob
Get-VBRSession -Type SimpleBackupCopyPolicy | where {$_.JobId -eq $backupCopy.Id}
Best regards,
Oleg
GregorS
Veeam ProPartner
Posts: 58
Liked: 13 times
Joined: Apr 10, 2013 12:11 pm
Full Name: Gregor Smerke
Location: Ljubljana, SI - Slovenia
Contact:

Re: From Restore Point to Backup Session First Run Start Time

Post by GregorS »

Hmm... your code also returns just the latest backup copy session without previous ones. Can you confirm? The behaviour is the same as with:

Code: Select all

Get-VBRSession -Job (Get-VBRJob -Name "A Backup Copy Job")
oleg.feoktistov
Veeam Software
Posts: 2021
Liked: 673 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: From Restore Point to Backup Session First Run Start Time

Post by oleg.feoktistov »

So I did a bit of research, turns out the parent policy session is always one for a particular backup copy job. It aggregates state for the last 24 hours and always exists as an initialization container. You can make sure it is the same session by monitoring its id - it doesn't change, but when you run another session worker, parent session's creation time, for instance, will begin to correspond to the worker session's creation time. That being said, sounds like, what you are after is a worker session creation time:

Code: Select all

$backupCopy = Get-VBRJob -Name 'Backup Copy Job 1'
$sessions = Get-VBRBackupSession -Name "$($backupCopy.Name)*"
$sessions | select Name, CreationTime
There is a hint in the UI suggesting that parent session is just a 24-hour state aggregation: when you click on the running backup copy job, you will see THROUGHPUT (LAST 24 HOURS) vs. THROUGHPUT (ALL TIME) in session worker view in History tab.

Let me know if it helps.

Best regards,
Oleg
GregorS
Veeam ProPartner
Posts: 58
Liked: 13 times
Joined: Apr 10, 2013 12:11 pm
Full Name: Gregor Smerke
Location: Ljubljana, SI - Slovenia
Contact:

Re: From Restore Point to Backup Session First Run Start Time

Post by GregorS »

Oleg, thanks for bearing with me. I'll try to explain with an example for what I'm after. I have a backup copy job with four source backup jobs that creates four worker jobs:

Code: Select all

PS> Get-VBRBackupCopyJob | Format-List -Property "Name", "Type", "BackupJob"

Name      : Primary Backup Copy Job
Type      : ImmediateBackupCopy
BackupJob : {Agent Backup Job for comp1, Agent Backup Job for comp2, VM Backup Job, Agent Backup Job for comp3}
If I use the following code, I can get a start time for each worker:

Code: Select all

PS> Get-VBRJob -Name "Primary Backup Copy Job" | ForEach-Object {$_.FindLastBackup()} | Get-VBRRestorePoint | Select-Object -Property "Name", "JobRunId", @{Name = "CreationTime"; Expression = {(Get-VBRSession -Id $_.JobRunId).CreationTime}}, "Type", @{Name = "Size"; Expression = {$_.GetStorage().Stats.BackupSize}} | Sort-Object -Property "CreationTime" | Format-Table

Name   JobRunId                             CreationTime            Type          Size
----   --------                             ------------            ----          ----
comp1 57f4e351-2a7e-4777-8346-436150a960ad 02.09.2024 00:00:19      Full  203784900608
VM1   72eb9f55-329a-48e4-8970-1cb0335eda3a 02.09.2024 00:00:20      Full   94289817600
VM2   72eb9f55-329a-48e4-8970-1cb0335eda3a 02.09.2024 00:00:20      Full    3991150592
VM3   72eb9f55-329a-48e4-8970-1cb0335eda3a 02.09.2024 00:00:20      Full    3283505152
comp2 1d735271-502b-4bd8-91f8-fe61f5392629 02.09.2024 00:00:27      Full 1463784570880
comp3 055cea6f-6216-431e-ad99-2e377dc3ca3c 02.09.2024 00:00:27      Full  241093869568
VM1   c4a1d17e-0856-4baa-9278-22445fac45c3 03.09.2024 00:00:10 Increment     849342464
VM2   c4a1d17e-0856-4baa-9278-22445fac45c3 03.09.2024 00:00:10 Increment      98607104
VM3   c4a1d17e-0856-4baa-9278-22445fac45c3 03.09.2024 00:00:10 Increment     255275008
comp1 be74e24c-e0f8-41b6-a644-c07f3c99cc99 03.09.2024 00:00:16 Increment    9518735360
comp2 eee1ff9b-97cf-4657-a1f5-d192ac9d7221 03.09.2024 00:00:17 Increment   66739941376
comp3 41a72a79-ab33-45ec-9291-121a8ec3fe13 03.09.2024 00:00:17 Increment   15876513792
Now, what I need is to get a start time of the "cover" backup copy job, which started the four workers and aggregate the restore point sizes by that. In the example above that would correspond to "02.09.2024 00:00:19" and "03.09.2024 00:00:10". Otherwise, I have no basis to group together all restore points that correspond to a job run as defined in the backup copy job schedule. (please delete the preceding post)
GregorS
Veeam ProPartner
Posts: 58
Liked: 13 times
Joined: Apr 10, 2013 12:11 pm
Full Name: Gregor Smerke
Location: Ljubljana, SI - Slovenia
Contact:

Re: From Restore Point to Backup Session First Run Start Time

Post by GregorS »

I ended up with a hack, cutting seconds and fractions of a second from restore point's creation time. This will only work if all copy job's worker jobs are initiated within a minute.

Code: Select all

@{Name = "CreationTime"; Expression = {Get-Date -Date (Get-VBRSession -Id $_.JobRunId).CreationTime.ToString("dd.MM.yyyy HH:mm")}}
oleg.feoktistov
Veeam Software
Posts: 2021
Liked: 673 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: From Restore Point to Backup Session First Run Start Time

Post by oleg.feoktistov »

Hi Gregor,

Apologies, I was mostly unavailable last week. I discussed it further with the developers and turns out my assumptions were correct. The worker sessions don't have parent sessions on the backend, so we cannot query it in powershell. What you see in the UI when clicking on a particular job is just an aggregated data for the last runs executed. So, this aggregation session does not relate as a parent to worker sessions you see, they are completely independent (one worker session = one backup copy job run). Hence, the only property you can rely on is worker session's CreationTime.

Best regards,
Oleg
GregorS
Veeam ProPartner
Posts: 58
Liked: 13 times
Joined: Apr 10, 2013 12:11 pm
Full Name: Gregor Smerke
Location: Ljubljana, SI - Slovenia
Contact:

Re: From Restore Point to Backup Session First Run Start Time

Post by GregorS »

Thanks, Oleg, for confirming this. I'll use my "truncate to a minute" hack for now or I'll invent something more sophisticated later if it stops producing good results. Here’s a sample report my script produces:

Code: Select all

CreationTime     DayOfWeek Type        SizeGB SizeTB
------------     --------- ----        ------ ------
11.09.2024 12:00 Wednesday Increment    30,38   0,03
11.09.2024 06:00 Wednesday Increment    44,77   0,04
10.09.2024 18:00   Tuesday Increment    22,25   0,02
10.09.2024 12:00   Tuesday Increment    17,85   0,02
10.09.2024 06:00   Tuesday Increment    21,29   0,02
09.09.2024 18:00    Monday Increment    23,98   0,02
09.09.2024 12:00    Monday Increment    22,23   0,02
09.09.2024 06:00    Monday Increment    18,12   0,02
08.09.2024 18:00    Sunday Increment    15,14   0,01
08.09.2024 12:00    Sunday Increment    10,93   0,01
08.09.2024 06:00    Sunday Increment    20,25   0,02
07.09.2024 18:00  Saturday Increment    12,67   0,01
07.09.2024 12:00  Saturday Increment    17,16   0,02
07.09.2024 06:00  Saturday Full      2.083,06   2,03
06.09.2024 18:00    Friday Increment    16,41   0,02
06.09.2024 12:00    Friday Increment    23,44   0,02
06.09.2024 06:00    Friday Increment    22,35   0,02
05.09.2024 18:00  Thursday Increment    17,27   0,02
05.09.2024 12:00  Thursday Increment    23,24   0,02
05.09.2024 06:00  Thursday Increment    23,59   0,02
04.09.2024 18:00 Wednesday Increment    22,50   0,02
04.09.2024 12:00 Wednesday Increment    29,44   0,03
04.09.2024 06:00 Wednesday Increment    24,22   0,02
03.09.2024 18:00   Tuesday Increment    20,84   0,02
03.09.2024 12:00   Tuesday Increment    34,60   0,03
03.09.2024 06:00   Tuesday Increment    21,57   0,02
02.09.2024 18:00    Monday Increment    23,99   0,02
02.09.2024 12:00    Monday Increment    20,63   0,02
02.09.2024 06:00    Monday Increment    20,05   0,02
01.09.2024 18:00    Sunday Increment    14,18   0,01
01.09.2024 12:00    Sunday Increment     9,54   0,01
01.09.2024 06:00    Sunday Increment    21,91   0,02
31.08.2024 18:00  Saturday Increment    15,41   0,02
31.08.2024 12:00  Saturday Increment    13,44   0,01
31.08.2024 06:00  Saturday Full      2.078,45   2,03


Total:                         Count   SizeGB SizeTB
------------------------------------   ------ ------
                                  35 4.857,13   4,74
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests