Restore Azure VM

Steps to restore AzureRM VM

This information is outdated. Please refer to the links at the bottom of this page for the latest information.

1. Restore the VM from “Backup Item” in the Vault and select Restore Type as “Restore disks”.

2. Download the three .json files which have been created along with the VHD in the container of the storage account.

3. Login to Azure via PowerShell

PS C:\Windows\system32> Connect-AzAccount

4. Find the id of the availability set

PS C:\Windows\system32> Get-AzAvailabilitySet -ResourceGroupName "xxx"

5. Find the following information below from the .json files which were downloaded in Step.2

– VM-Size (e.g. Standard_DS2_v2_Promo)

– OS Disk URI (e.g. https://xxxxx/xxxxx/xxxx.vhd)

– NIC ID (e.g /subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Network/networkInterfaces/xxx)

– Location (e.g. australiasoutheast)

6-1. Run the commands below if using unmanaged disk (Storage Account)

PS C:\Windows\system32> $vm = New-AzureRmVMConfig -VMName <VM-name> -VMSize <vm-size> -AvailabilitySetId <availability-set-id> 

PS C:\Windows\system32> Set-AzureRmVMOSDisk -CreateOption "Attach" -VM $vm -VhdUri <osDiskURI> -Name <osDiskName> [-Windows | -Linux] 

----- If Data Disks available -----
PS C:\Windows\system32> Add-AzureRmVMDataDisk -VM $vm -Name <DataDiskName> -VhdUri <DataDiskURI> -Lun <LUN#> -CreateOption Attach 
-----------------------------------

PS C:\Windows\system32> Add-AzureRmVMNetworkInterface -VM $vm -Id <nicId> 

PS C:\Windows\system32> New-AzureRmVM -ResourceGroupName <resourceGroupName> -Location <location> -VM $vm

6-2. Run the command below if using managed disk

#Provide the name of your resource group 
$resourceGroupName ='xxx' 

#Provide the name of the snapshot that will be used to create OS disk 
$snapshotName = 'xxx' 

#Provide the name of the OS disk that will be created using the snapshot 
$osDiskName = 'xxx'

#Provide the name of the Nic
$nicName = 'xxx'

#Provide the name of the VM
$myvm = 'xxx'

#Provide the VM Size
$vmsize = 'xxx'

##########

$snapshot = Get-AzSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName 

$diskConfig = New-AzDiskConfig -Location $snapshot.Location -SourceResourceId $snapshot.Id -CreateOption Copy 

$disk = New-AzDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $osDiskName 

$nic = Get-AzNetworkInterface -Name $nicName

# If AvailabilitySet is configured
$ava = Get-AzAvailabilitySet -ResourceGroupName $resourceGroupName
$vm = New-AzVMConfig -VMSize $vmsize -VMName $myvm -AvailabilitySetId $ava.Id

## If AvailabilitySet is NOT configured
#$vm = New-AzVMConfig -VMSize $vmsize -VMName $myvm

# Set the VM configuration to point to the new disk   
Set-AzVMOSDisk -VM $vm -ManagedDiskId $disk.Id -Name $disk.Name -CreateOption Attach -Windows

Add-AzVMNetworkInterface -VM $vm -ID $nic.Id

New-AzVM -ResourceGroupName $resourceGroupName -VM $vm -Location $disk.Location

7. Set Auto-Shutdown if necessary

Reference :

Restoring via PowerShell

https://docs.microsoft.com/en-us/azure/backup/backup-azure-vms-automation

Create a virtual machine using an existing managed OS disk with PowerShell

https://docs.microsoft.com/en-us/azure/virtual-machines/scripts/virtual-machines-windows-powershell-sample-create-vm-from-managed-os-disks?toc=%2fpowershell%2fmodule%2ftoc.json

Leave a Reply

Your email address will not be published. Required fields are marked *