I am struggling to filter the restore only to latest point that is originating in local SOBR. Any idea how to ignore other backups?
powershell script that should restore VM named "ADDC" from latest RP found only in jobs with local destination.
The destination is on this VBR server, local drive.
Code: Select all
$allBackups = Get-VBRBackup | Where-Object { ($_."Name" -notlike "Remote*") -and ($_.JobType -eq "Backup")}
# I want to recover these VMs
$VMsRestorePlanned = @('ADDC')
$VMsRestoreFinished = @()
foreach ($backup in $allBackups) {
$allObjects = $backup.GetObjects()
foreach ($object in $allObjects) {
if ($VMsRestorePlanned.Contains($object.Name)) {
Write-Host "'$($object.name)' found in backup '$($backup.Name)'"
# dupe prevention
if ($VMsRestoreFinished.Contains($object.Name)) {
Write-Error "'$($object.name)' has been already recovered. Select the VMs, that are in filtered backups contained just once!'"
}
# let's find latest restore point
$allRestorePoints = $backup | Get-VBRRestorePoint -Name $object.Name -Verbose
$restorePoint = $allRestorePoints | Sort-Object -Property "CreationTime" -Descending | select -first 1
Write-Host "... from $($restorePoint.creationTime)"
$params = @{
RestorePoint = $VMLastRestorePoint
Server = 'lab.example.com'
Path = 'D:\VMs\LAB-x-delete'
VMName = 'LAB-x-ADDC'
PreserveVmID = $false
PowerUp = $false
NICsEnabled = $false
Reason = 'lab creation'
RunAsync = $true
}
Start-VBRHvRestoreVM @params
}
}
}
Problem: The script runs the restore from remote copy job.
I have no idea if the problem is introduced in the first filter or later in the code. And I do not understand the difference between Get-VBRBackup and Get-VBRJob correctly (but I need to use the Get-VBRBackup because of subsequent cmdlets that accept it as a parameter).
However job names in "Get-VBRBackup" are not matching job names shown in VBR console, contrary to command "Get-VBRJob"