PowerShell script exchange
Post Reply
Friday2
Novice
Posts: 3
Liked: never
Joined: Sep 22, 2020 1:31 pm
Contact:

Cross hypervisor instant vm recovery

Post by Friday2 »

Now with Veeam10 it's possible to do cross hypervisor instant VMrecoveries. So i was thinking about automating part of the migration process from Hyper-V to VMware for us.

I've got this snippet so far. But it reports error

Code: Select all

Add-PSSnapin VeeamPSSnapin

$servers = Get-VBRServer | Where-Object { $_.Type -match "ESXi" -and $_.Name -match "172.21.41." }

$ctr = 0
foreach ($vm in Get-VBRJob -Name "migrationjob" | Select-Object @{Name="vms"; Expression={ $_.GetObjectsInJob().name }} | Select-Object -ExpandProperty "vms") {
    while ($ctr -ge $servers.Count) {
        $ctr -= $servers.Count
    }

    $restorepoint = Get-VBRBackup -Name "migrationjob" | Get-VBRRestorePoint | Where-Object { $_.Name -eq $vm } | Sort-Object -Property CreationTimeUtc -Descending | Select-Object -First 1
    $restorepoint
    Start-VBRInstantRecovery - -RestorePoint $restorepoint -Server $servers[$ctr] -PowerUp 
    start-vbr

    $ctr++
}

Code: Select all

Start-VBRInstantRecovery : Failed to process RestorePoint 49dbc84c-0726-4742-8718-492b3815d537. Platform type EHyperV is not supported
At C:\Users\randomized\Desktop\instantvmrecovery.ps1:13 char:5
+     Start-VBRInstantRecovery -RestorePoint $restorepoint -Server $ser ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Start-VBRInstantRecovery], Exception
    + FullyQualifiedErrorId : System.Exception,Veeam.Backup.PowerShell.Cmdlets.StartVBRInstantRecovery
So the scripts gets all vms in a job, loops them, gets the latest restorepoint for each of them, then it should start an instant vm recovery (We're "load balancing" servers across all hosts available in the cluster as well), this is where it fails with the error that Hyper-V isn't a supported platform (Which it wasn't until Veeam 10 if i understand correctly).

I've looked through all cmdlets containing "instant" but it seems like there's no "specialized" version for doing Hyper-V to VMware in here as of now.

Code: Select all

PS C:\Windows\system32> Get-Command | Where-Object { $_.Name -match "instant" }

CommandType     Name                                               Version    Source                                                                                                                                      
-----------     ----                                               -------    ------                                                                                                                                      
Cmdlet          Get-VBRInstantRecovery                             10.0.0.0   VeeamPSSnapin                                                                                                                               
Cmdlet          Restart-VBRInstantRecovery                         10.0.0.0   VeeamPSSnapin                                                                                                                               
Cmdlet          Start-VBREpInstantRecovery                         10.0.0.0   VeeamPSSnapin                                                                                                                               
Cmdlet          Start-VBRHvInstantRecovery                         10.0.0.0   VeeamPSSnapin                                                                                                                               
Cmdlet          Start-VBRHvInstantRecoveryMigration                10.0.0.0   VeeamPSSnapin                                                                                                                               
Cmdlet          Start-VBRInstantRecovery                           10.0.0.0   VeeamPSSnapin                                                                                                                               
Cmdlet          Start-VBRvCloudInstantRecovery                     10.0.0.0   VeeamPSSnapin                                                                                                                               
Cmdlet          Start-VBRViComputerInstantRecovery                 10.0.0.0   VeeamPSSnapin                                                                                                                               
Cmdlet          Start-VBRViInstantVMDiskRecovery                   10.0.0.0   VeeamPSSnapin                                                                                                                               
Cmdlet          Stop-VBRInstantRecovery                            10.0.0.0   VeeamPSSnapin                                                                                                                               
Cmdlet          Stop-VBRViInstantVMDiskRecovery                    10.0.0.0   VeeamPSSnapin    
Thoughts on how this could be achieved? We're on Veeam 10.0.0.4461
HannesK
Product Manager
Posts: 14839
Liked: 3086 times
Joined: Sep 01, 2014 11:46 am
Full Name: Hannes Kasparick
Location: Austria
Contact:

Re: Cross hypervisor instant vm recovery

Post by HannesK » 1 person likes this post

Hello,
I did not test, but in the list you mention, there is Start-VBRViComputerInstantRecovery... and the user guide says for that cmdlet https://helpcenter.veeam.com/docs/backu ... ml?ver=100
Hyper-V workloads to restore them to VMware vSphere VMs.
Does that work?

Best regards,
Hannes
Friday2
Novice
Posts: 3
Liked: never
Joined: Sep 22, 2020 1:31 pm
Contact:

Re: Cross hypervisor instant vm recovery

Post by Friday2 »

This seems to do the job indeed, if i knew relations between objects better i could probably have shaved it a bit, but it works.

Thanks Hannes!

Code: Select all

Function Start-Countdown {
    Param(
        [Int32]$Seconds = 10,
        [string]$Message = "Pausing for 10 seconds..."
    )
    $curtime = [int][double]::Parse((Get-Date -UFormat %s))
    $endtime = $curtime + $Seconds
    while ($curtime -lt $endtime) {
        $curtime = [int][double]::Parse((Get-Date -UFormat %s))
        Write-Progress -Id 1 -Activity $Message -Status "Waiting for $Seconds seconds, $($endtime - $curtime) seconds left" -PercentComplete (($endtime - $curtime) / $Seconds * 100)
        Start-Sleep -Seconds 1
    }
    Write-Progress -Id 1 -Activity $Message -Status "Completed" -PercentComplete 100 -Completed
}

Start-Countdown -Seconds 6326 -Message "Waiting to execute final backup"
Add-PSSnapin VeeamPSSnapin
Start-VBRJob 16a3fbc7-efef-4433-b515-cce532e11e13

$servers = Get-VBRServer | Where-Object { $_.Type -match "ESXi" -and $_.Name -match "172.21.41." }

$ctr = 0
foreach ($vm in Get-VBRJob -Name "migrationjob" | Select-Object @{Name="vms"; Expression={ $_.GetObjectsInJob().name }} | Select-Object -ExpandProperty "vms") {
    while ($ctr -ge $servers.Count) {
        $ctr -= $servers.Count
    }
    $server = $servers[$ctr] # Server used for migrating this machine. Seems to increase speeds
    $vmname = $vm.Replace(" ", "_")

    $restorepoint = Get-VBRBackup -Name "migrationjob" | Get-VBRRestorePoint | Where-Object { $_.Name -eq $vm } | Sort-Object -Property CreationTimeUtc -Descending | Select-Object -First 1
    Start-VBRViComputerInstantRecovery -RestorePoint $restorepoint -Server $server -PowerOnAfterRestoring -RestoredVMName $vmname
    $datastore = Find-VBRViDatastore -Server $server -Name "vsanDatastore"
    Start-VBRQuickMigration -Server $server -Datastore $datastore -Entity (Find-VBRViEntity -Name $vmname) -RunAsync

    $ctr++
}
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Cross hypervisor instant vm recovery

Post by oleg.feoktistov » 4 people like this post

Hi @Friday2,

Check out Powershell Cookbook module and Show-Object cmdlet specifically. It'll help you to sneak under each object's declared properties/methods and understand relations between classes better. For example:

Code: Select all

Get-VBRJob | Show-Object
We use it quite often and it does save us some time.

Thanks,
Oleg
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests