PowerShell script exchange
Post Reply
SolonasLouca
Novice
Posts: 3
Liked: never
Joined: Oct 11, 2023 8:46 am
Full Name: Solonas Louca
Contact:

Get-VBRRestorePoint help

Post by SolonasLouca »

Hello, I am trying to export the results for each job, containing name of the job, VM name, and last restore point and whether it's full or incremental.

Up to now, I am using this, but it only provides vm name and job name.

Code: Select all

Get-VBRRestorePoint | select name, {$_.FindSourceJob().name}  | Export-Csv c:\temp\RestorePoints\result.csv
oleg.feoktistov
Veeam Software
Posts: 2015
Liked: 671 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Get-VBRRestorePoint help

Post by oleg.feoktistov »

Hi,

In this case I'd script something like this:

Code: Select all

$ErrorActionPreference = "SilentlyContinue"

$jobs = Get-VBRJob 
$backups = Get-VBRBackup
foreach ($job in $jobs) {
  $backup = $backups | where {$_.JobId -eq $job.Id}
  $childBackups = $backup.FindChildBackups()
  foreach ($child in $childBackups) {
  $lastRp = Get-VBRRestorePoint -Backup $child | sort -Property CreationTime -Descending | select -First 1
  $lastRp | select @{n='LastRestorePointId';e={$lastRp.Id}}, @{n='JobName';e={$job.Name}}, Type

  }
}
Best regards,
Oleg
SolonasLouca
Novice
Posts: 3
Liked: never
Joined: Oct 11, 2023 8:46 am
Full Name: Solonas Louca
Contact:

Re: Get-VBRRestorePoint help

Post by SolonasLouca »

thanks for your help! tried to add the number of restore points & show each VM with their job name on a separate line but failing.
sorry but I'm new on PowerShell ;p
david.domask
Veeam Software
Posts: 2331
Liked: 554 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Get-VBRRestorePoint help

Post by david.domask »

HI @SolonasLouca,

Try using the Group-Object cmdlet from Powershell: https://learn.microsoft.com/en-us/power ... rshell-7.3

Oleg's script will return the _last_ Restore Point (RP), so you can edit Oleg's code and remove the piping to the Sort and Select statements and just save all the RPs to some array -- then pass the array to Select to get the relevant properties you want to display/print, then pass that to Group-Object -Property and pick the property to filter on. I think ObjectID would be best to group on or the VMName property.

Else, we can save the Get-VBRBackup call I think as COib objects have a property JobRunID which is an ID you can pass to Get-VBRBackupSession -Id parameter and the resulting CBackupSessionObject has Job Name on it.

Try this code:

Code: Select all

$RPReport = [System.Collections.Generic.List[PSObject]]@()
$RPs = Get-VBRRestorePoint | Sort-Object -Property BackupID, CreationTime -Descending
Foreach($r in $RPs){
	$JobName = (Get-VBRBackupSession -ID $r.JobRunID).JobName
	$RPReportData = [PSCustomObject]@{
		JobName = $JobName
		RestorePointID = $r.id
		VMName = $r.VMName
		CreationTime = $r.CreationTime
	}
	$RPReport.Add($RPReportData)
}
$RPReport will have the custom object built in the ForEach loop, then you can play with Group-Object and get it to print however you like. Give it a shot.
David Domask | Product Management: Principal Analyst
SolonasLouca
Novice
Posts: 3
Liked: never
Joined: Oct 11, 2023 8:46 am
Full Name: Solonas Louca
Contact:

Re: Get-VBRRestorePoint help

Post by SolonasLouca »

almost sorted out. the only think i'm missing, is the number of retention points :)
david.domask
Veeam Software
Posts: 2331
Liked: 554 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Get-VBRRestorePoint help

Post by david.domask »

Aha, play with Group-Object a bit and see what it does -- try passing $RPReport to Group-Object -Property VMName and you'll see what I mean.

I'm not being coy, it's just the formatting is very much so individual preference, so I'm not sure what you want, it's best to play with it a bit in your lab :).

Consider looping over the $RPReport List and then using the Group-Object cmdlet based on the job names you want to group. For example, I punched this out in my lab quick:

Code: Select all

$ErrorActionPreference = "SilentlyContinue"
	
$RPReport = [System.Collections.Generic.List[PSObject]]@()
$RPs = Get-VBRRestorePoint | Sort-Object -Property BackupID, CreationTime -Descending
Foreach($r in $RPs){
	$JobName = (Get-VBRBackupSession -ID $r.JobRunID).JobName
	$RPReportData = [PSCustomObject]@{
		JobName = $JobName
		RestorePointID = $r.id
		VMName = $r.VMName
		CreationTime = $r.CreationTime
	}
	$RPReport.Add($RPReportData)
}


$AllJobNames = $RPReport.JobName | Sort-Object -Unique
Foreach($jn in $AllJobNames){
	$JobRPs = $RPReport | Where-Object {$_.JobName -eq $jn}
	$RPGroup = $TestRP | Group-Object -Property VMName
	$RPGroup | Select Name, Count, @{n='Job Name';e={$jn}}
}
The output is something like:

Code: Select all

Name                Count Job Name
----                ----- --------
ddom-tinyvm_replica   111 ddom-test
ddom-tinyvm           112 ddom-test
ddom-tinyvm_replica   111 ddom-tinyvm_2023-04-26T151641
ddom-tinyvm           112 ddom-tinyvm_2023-04-26T151641
ddom-tinyvm_replica   111 ddom-tinyvm_2023-04-26T152525
ddom-tinyvm           112 ddom-tinyvm_2023-04-26T152525
ddom-tinyvm_replica   111 ddom-tinyvm_2023-04-26T152743
ddom-tinyvm           112 ddom-tinyvm_2023-04-26T152743
ddom-tinyvm_replica   111 ddom-tinyvm_2023-08-11T121553
ddom-tinyvm           112 ddom-tinyvm_2023-08-11T121553
ddom-tinyvm_replica   111 ddom-tinyvm_2023-08-11T121655
ddom-tinyvm           112 ddom-tinyvm_2023-08-11T121655
ddom-tinyvm_replica   111 ddom-tiny-vm-offload-manual
ddom-tinyvm           112 ddom-tiny-vm-offload-manual
ddom-tinyvm_replica   111 gfs-direct-test
ddom-tinyvm           112 gfs-direct-test
ddom-tinyvm_replica   111 gfs-direct-test_clone1
ddom-tinyvm           112 gfs-direct-test_clone1
ddom-tinyvm_replica   111 gfs-test_clone1
ddom-tinyvm           112 gfs-test_clone1
ddom-tinyvm_replica   111 quick-encrypt
ddom-tinyvm           112 quick-encrypt
ddom-tinyvm_replica   111 script-test
ddom-tinyvm           112 script-test
ddom-tinyvm_replica   111 sstest
ddom-tinyvm           112 sstest
ddom-tinyvm_replica   111 vmware-direct-objstg
ddom-tinyvm           112 vmware-direct-objstg
ddom-tinyvm_replica   111 vmware-ffi-cap-bb
ddom-tinyvm           112 vmware-ffi-cap-bb
ddom-tinyvm_replica   111 vmware-per-job
ddom-tinyvm           112 vmware-per-job
Since it's a lab for me obviously i'm just backing up a few VMs, but you can get an idea on how to do your formatting with this. Play around with what data you want in the first loop and how you want to group in the second group and see what you end up with. The formatting is purely Powershell side work so it'll just depend on you for what you want to see :)
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests