Veeam has a fairly loose association between jobs and backups. This makes sense because it's completely possible to delete a job and still have backups on disk, or delete the backups for a job and still have the job and all session data in the database. However, assuming the job session data and backup data is still current, it is possible to determine the association between a backup session ID and a restore point ID. Once you've associated a specific backup session to a specific restore point ID, you can then match the individual task sessions and restore points by object ID. Here is a simple example:
Code: Select all
$JobName = "<Name_of_Job>"
# Get a backup session for the job (in this example I'm just grabbing the most recent)
$JobSessions = Get-VBRBackupSession | ?{$_.JobName -eq $JobName} | Sort -Property CreationTime | Select -Last 1
# Get the task sessions for the specific backup session
$TaskSessions = $JobSessions | Get-VBRTaskSession
# Get the restore points for the specific backup session
$RestorePoints = Get-VBRBackup -Name $JobName | Get-VBRRestorePoint | ?{$_.PointId -eq $JobSessions.CurrentPointId}
# Now that we have the task sessions and restore points for the given job session we can match them up via ObjectID
# This example just loops through each task session and displays the associated restore point
ForEach ($TaskSession in $TaskSessions) {
$RestorePoints | ?{$_.ObjectId -eq $TaskSession.Info.ObjectId}
}
Note that the above code has no logic for dealing with error'd sessions, you could potentially filter out sessions that did not end in success or warning state, and also filter out incomplete restore points (perhaps using the IsCorrupted flag for example). Also, in the example above I'm just grabbing the most recent backup session, however, it's totally possible to grab any session, including sessions where the restore points are no longer on disk due to retention since session history is commonly kept much longer than restore points. In that case the query for restore points will return no points for the specific session.
There may be a better way to do this, but this is the simplest method that I've found. Also, if you are reporting on many jobs/sessions it's easy to have the code collect all Backup Sessions, Task Sessions, and Restores Points for all jobs into variables at the start of the script and then just filter out the data as needed.