Powershell Automates Multiple Instant Recoveries

When you hit a disaster you want to recover all your important VMs as soon as possible but usually going through UI to individually restore VMs and define their new location is a slow process that you may want to avoid under a stressfull situation like a disaster and you need an automated one-click solution.

Unitrends Enterprise Plus edition provides the ability to automate recovery across multiple machines, both virtual and physical but if you dont have Enterprise Plus license in this post we are going to explain how you can do it by yourself using powershell and Unitrends REST API.

If you have been following our PowerShell Toolkit blog series you will be already familiar running Unitrends Powershell Cmdlets, if not you can get started reading this Unitrends Powershell Toolkit article.

How to use new Instant Recovery Cmdlets

  • You can explore your Backup Catalog to get a list of VMs that you can recover
PS> Get-UebCatalog
instance_id database_name      last_backup_date       system_name
----------- -------------      ----------------       -----------
313         SQL01              01/24/2016 03:01:09 am ueb08
  • Get Backup Id of the VM you want to restore
PS> Get-UebBackup -VM SQL01

  id type        start_date             system_name
  -- ----        ----------             -----------
1609 Incremental 01/24/2016 03:01:09 am
1544 Incremental 01/21/2016 09:27:43 pm
  • Find out ESX Host ID where you want to restore the VM.
PS> (Get-UebApi -uri "/api/restore/targets").targets

                                  id name                        datastores
                                  -- ----                        ----------
38373035-3436-5a43-4a39-343430343745 esx145.lab.unitrends.com    {@{name=TINTRI; total_size_gb=31216,5; free_size_gb=8174,4}}
38373035-3436-5a43-4a39-353030314d53 esx147.lab.unitrends.com    {@{name=TINTRI; total_size_gb=31216,5; free_size_gb=8174,4}}
38373035-3436-5a43-4a30-313630374752 esx148.lab.unitrends.com    {@{name=TINTRI; total_size_gb=31216,5; free_size_gb=8174,4}}
  • Find out appliance IP address you want to use for IR
PS>  (Get-UebApi -uri "/api/networks").networks.ip
  • Start Instant Recovery
Start-UebIr -Host 38373035-3436-5a43-4a39-343430343745 -Name SQL01_restore -Datastore TINTRI -BackupId 1609 -Address
  • Monitor Instant Recovery status
PS> Get-UebIr

virtual_id vm_name        status    mode
---------- -------        ------    ----
313.vm_ir  SQL01_restore available Audit
  • Stop Instant Recovery when you are done
PS> Stop-UebIr -Id 313.vm_ir


How to restore multiple VMs with one command

With this information we are ready to create a custom powershell script to restore multiple VMs using these cmdlets.

The logic of the script will find out latest available backup for each VM included in the list and will restore them to a predefined target locations (Host, Datastore, etc).

  • Create Custom Recovery Script (RecoveryPlan_1.ps1)

# USER DEFINED SETTINGS (change to your enviroment settings !!!)
$ESXHost = "38373035-3436-5a43-4a39-343430343745"
$Datastore = "TINTRI"
$UebIp = ""
$VMs = @("SQL01","WEB01","WEB02") #List of VMs to restore
$VMextension = "_restore"

foreach($vm in $VMs)
    $Name = $($vm + $VMextension)
    Write-Host "Recovering VM $vm as $Name"
    $lastbackup = Get-UebBackup -VM $vm | Sort-Object -Property start_date -Descending | Select-Object -First 1
    Start-UebIr -Host $ESXHost -Name $Name -Datastore $Datastore -BackupId $lastbackup.id -Address $UebIp

Write-Host "Recovered VM Status:"
  • Running the Script
PS c:\unitrends-pstoolkit\Scripts> .\RecoveryPlan_1.ps1
 [*] Recovering VM SQL01 as SQL01_restore
 [*] Recovering VM WEB01 as WEB01_restore
 [*] Recovering VM WEB02 as WEB02_restore

virtual_id vm_name status mode
---------- ------- ------ ----
313.vm_ir SQL01_restore available Audit
30.vm_ir WEB01_restore available Audit
51.vm_ir WEB02_restore available Audit

And that is! all VMs that you included in the list have been recovered just running one command.

You can adapt and extend this script if you have other requeriments, it is just a sample of how you can extend Unitrends Enteprise Backup out-of-the-box features using REST APIs and Powershell.

Unitrends Enterprise Plus

If you dont want to mantain scripts Unitrends Enterprise Plus solves this problem allowing you to create recovery plans to automate failover of multiple VMs, network reconfiguration and recovery assurance to be sure your backups are tested and not corrupted and that you are going to be able to recover from them matching your RPO/RTO.


Discover how Unitrends can help protect your organization's sensitive data