Technical Thursday – Restore VM from RSV – managed disk

Last week I provided the unmanaged disk related restore description which based on the concept for restore and now I show the managed disk related restore steps on technical level.

 

Some useful information before you start the restore:

Required naming convention

OS disk and Data disks related vhds must be in the following format:

  • OS disk:
    • [vmname]-osdisk
  • Data disk:
    • [vmname]-datadisk-[diskid] (where the diskid represents the value of lun)
    • (example for 1st data disk: myvm-datadisk-0)

Prerequisites

  • Linux OS
  • Azure-Cli 2.x
  • Python 2.7
  • amaretto (Azure management tools by the1bit) package for python. You can download it from pypi and git as well.

 

For this type of restore we can use the previously introduced amaretto python package. This package contains the restore steps related functions one-by-one. Additionally you can also find a restoreManagedDiskFromVhd function in amarettorestore module which “do your job” regarding restore procedure.

What does this function do?

  1. Get restore file from restored container
  2. Download deploy file (generally this is a config.json with UTF-16 encoding(!))
  3. Check file encoding – if necessary it converts from UTF-16 to UTF-8
  4. Deallocate VM
  5. Delete VM object (ONLY)
  6. Get os disk information (size, tags – it is important from billing and categorization point of view)
  7. Delete old managed disk
  8. Convert vhd to managed disk (with tags and sizes from step 6)
  9. Get data disks information (size, tags – it is important from billing and categorization point of view)
  10. Delete old managed disks one-by-one
  11. Convert vhds to managed disks (with tags and sizes from step 9)
  12. Check restore result (whether all disks are restored or not)

 

And now let’s see the restore steps one-by-one:

1. Restore VM’s VHDs from backup vault

Choose the right restore point from Recovery Services vaults which belongs to target VM and Restore OSDisk and DataDisks to your storage account.

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

Note: In case of manage disk restore: Template based restore for managed disks is planned in June 2018. Thus far that we should identify the restored VHDs. This means after the restore you have vhd files instead of managed disks. 🙁

2. Configure and execute “restoreManagedDiskFromVhd” function from amaretto

You have to execute the following commands with your VM related parameters from python:

# Your VM name
vmName = "thisismyserver-2"
# resource group name where the VM is located
resourceGroup = "thisismyrg"
# location where the resources are located. (westeurope, germanycentral, ...)
location = "westeurope"
# storage account name where the VM's restored vhds are stored
sourceStorageAccount = "thisismystorage"
# 1st or 2nd access key for sourceStorageAccount
sourceSecretKey = "d22j/rr+a7br7LW6KDKV8KZkO2wCIe3m0MTKVr3Tt9B9NMZZsYxny8bvWvPwUGgZpDkE8gyAePjWCVu2IZ4LYw=="
# name of container where the restored vhds are stored
sourceContainer = "vhd6bdda0e88c88408299246c468784656546a"
# managedDiskAccountType (optional): sku of disk. Possible values: Standard_LRS or Premium_LRS. Default value: Standard_LRS
# managedDiskAccountType = "Standard_LRS"
# Execute restore function
amaretto.amarettorestore.restoreManagedDiskFromVhd(vmName, resourceGroup, location, sourceStorageAccount, sourceSecretKey, sourceContainer)

Result:

>>> amaretto.amarettorestore.restoreManagedDiskFromVhd(vmName, resourceGroup, location, sourceStorageAccount, sourceSecretKey, sourceContainer)
2018-02-22 13:18:40 - FUNCTION Restore Managed disk based VM's vhds
2018-02-22 13:18:40 - Get restore file from restored container
2018-02-22 13:18:43 - Download deploy file
Finished[###############################]  100.0000%
2018-02-22 13:18:45 - Check config.json file encoding
2018-02-22 13:18:45 - Deallocate VM: thisismyserver-2
2018-02-22 13:18:48 - Delete VM object: thisismyserver-2
2018-02-22 13:18:50 - - OS DISK
2018-02-22 13:18:50 - Get os disk information
2018-02-22 13:18:50 - Delete old managed disk: thisismyserver-2-osdisk
2018-02-22 13:18:54 - Convert os vhd to its original location
2018-02-22 13:19:00 - - DATA DISKS
2018-02-22 13:19:00 - Get data disks information
2018-02-22 13:19:00 - Delete old data disk
2018-02-22 13:19:05 - Convert data disk to its original location: thisismyserver-2-datadisk-0
2018-02-22 13:19:11 - OS and Data disks are restored
True

3. Re-create target VM with your ARM Template

In this step you merely redeploy your vm from that ARM template you had created for original vm creation.

 

I hope it helps to solve your restore VM problem. 🙂

 

If you need some help regarding ARM Template for restore or other scenarios do not hesitate to contact me.

Be the first to comment on "Technical Thursday – Restore VM from RSV – managed disk"

Leave a comment