PowerShell script exchange
Post Reply
alesovodvojce
Enthusiast
Posts: 61
Liked: 9 times
Joined: Nov 29, 2016 10:09 pm
Contact:

restoring from specified backup repository or host

Post by alesovodvojce »

Hi,

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"
david.domask
Veeam Software
Posts: 1226
Liked: 322 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: restoring from specified backup repository or host

Post by david.domask »

Hi @alesovodvojce,

Try filtering Get-VBRBackup on the JobID property of the Primary Backup:

Code: Select all

PS C:\Users\Administrator> Get-VBRBackup |Where-Object {$_.JobID -eq $job.id}

Job Name                  Type            Creation Time               VM count
--------                  ----            -------------               --------
vmware-ffi-cap-bb         VMware Backup   4/13/2023 12:06:4...               2
David Domask | Product Management: Principal Analyst
alesovodvojce
Enthusiast
Posts: 61
Liked: 9 times
Joined: Nov 29, 2016 10:09 pm
Contact:

Re: restoring from specified backup repository or host

Post by alesovodvojce »

@david.domask, thanks for the fast reply!
It helped me in trying and ultimately find a source of problem, which was not in initial filtering, but in using wrong variable.
Because of that typo, the restore process started with some other backup chain than what we tried to filter.

The correct @params for restore should be instead the following

Code: Select all

$params = @{
                RestorePoint = $restorePoint 
                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
            }

And we try also this other way to filter only local and from SOBR backups.
Don't like to remember the exact backup job names, instead search for all and filter only the relevant. Might help someone

Code: Select all

# all jobs
$b = Get-VBRBackup
# list them
$b
# then manually find an exemplary local target job to SOBR, i.e. $b[2]
# $b[2].JobTargetHostId will be the guiid of local storage repo (note that) and
# $b[2].RepositoryType will have value 'ExtendableRepository' which should mean SOBR
# resulting the filter
$backupsFiltered = Get-VBRBackup | Where-Object { ($_.JobTargetHostId -eq '6745a759-2205-4cd2-b172-8ec8f7e60ef8') -and  ($_.IsBackup -eq $true) -and ($_.VMCount -gt 0) -and ($_.RepositoryType -eq 'ExtendableRepository') }
david.domask
Veeam Software
Posts: 1226
Liked: 322 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: restoring from specified backup repository or host

Post by david.domask »

Got it! Glad that you were able to figure it out @alesovodvojce :)

Your solution is quite fine; strings are the devil, so you want to avoid validating strings whenever possible and instead parse existing properties :) So this looks pretty stable IMO
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests