Skip to main content
Question

Get all backup session IDs for particular location


Could anyone help for the following scenario .

 

[Veeam.Backup.Core.CBackupSession]::GetAll()

 

For the above command do we have any commands as the above one not fetching all backup session ids done for particular location.

6 comments

ratkinsonuk
Forum|alt.badge.img+2
  • Comes here often
  • 50 comments
  • July 9, 2024

Any reason you’re not using Get-VBRBackupSession?

https://helpcenter.veeam.com/docs/backup/powershell/get-vbrbackupsession.html?ver=120

 

Rob.


Forum|alt.badge.img+3
  • Comes here often
  • 106 comments
  • July 9, 2024

Seconding @ratkinsonuk here, you are using unsupported .NET Reflection; I’m guessing it’s because Get-VBRBackupSession can be a bit slow.

Play around with Get-VBRSession. It has a parameter -Type which you can use to return limited session data information.

Get the Id from the returned sessions, and pass those sessions to Get-VBRBackupSession on the -Id parameter, it is much faster, and you can filter the resulting sessions afterwards in powershell by piping to Where-Object and comparing against the CreationTime property.

 

Example:

$tLogSessions = Get-VBRSession -Type SqlLogBackup
$tlogIds = $tLogSessions.Id
$tlogIds[0]

Guid
----
c6c591a0-fbce-4333-9a2f-686763507997


$bSess = Get-VBRBackupSession -Id $tlogIds
$bSess.count
	208
$tLogSessions.Count
	208
$date = Get-Date
$Last24HtLogSessions = $bSess | Where-Object {$_.CreationTime -ge $date.AddDays(-1)} | Sort -Property CreationTime -Descending
$Last24HtLogSessions | Select -First 10 #only 2 are running for me in last 24h, so only 2 results

Job Name             State      Start Time             End Time               Result
--------             -----      ----------             --------               ------
BJ-SQL-logshippin... Working    09.07.2024 07:30:31    01.01.1900 00:00:00    None
BJ-SQL-AOAG2016 S... Working    08.07.2024 22:15:40    01.01.1900 00:00:00    None

It should be noticeably faster, though it will still take time to process. Using the workaround above, first command took 20 seconds on a “cold” powershell session + another 10 seconds for the Get-VBRBackupSession command.

PS C:\Windows\system32> Measure-Command -Expression {Get-VBRSession -Type SQLLogBackup}
Seconds           : 20
Milliseconds      : 162

...
TotalSeconds      : 20,1626446

PS C:\Windows\system32> Measure-Command -Expression {Get-VBRBackupSession -id $sess.id}
Seconds           : 10
Milliseconds      : 774
...
TotalSeconds      : 10,7747928
 

Get-VBRbackupSession was still processing from a cold session as I was finishing this post, and it started first :)

 


ratkinsonuk
Forum|alt.badge.img+2
  • Comes here often
  • 50 comments
  • July 9, 2024

We (the community) have had a request in with R&D for some time now to add a date range parameter to the session commands. As you say David, it can be really slow. We have 180 days of history so you can imagine how slow some of our reporting is.

Rob.


Forum|alt.badge.img+3
  • Comes here often
  • 106 comments
  • July 9, 2024

Aha, understood Rob, and it’s on our radar, but nothing to share right now. The above workaround, while a little clumsy, has been my go-to if I need to do any large session related work with Powershell. But it is an element that is noted for some love and care, and the workarounds hopefully are sufficient for the time being. The above listed workaround is still a little “slow”, but significantly faster than Get-VBRBackupSession AND it’s supported ;)


ratkinsonuk
Forum|alt.badge.img+2
  • Comes here often
  • 50 comments
  • July 9, 2024

Apologies David. I wasn’t having a whinge - didn’t even realise you were from Veeam to be honest. It was more as info to the OP.

Rob.


Forum|alt.badge.img+3
  • Comes here often
  • 106 comments
  • July 9, 2024

All good Rob)) I don’t frequent the community forums often and just happened to be here for other reasons and thought it would be cool to know it’s been discussed internally. ;)


Comment