How to create snapshots for Azure managed disks

Today, Azure managed disks has a long list of benefits that make them the ideal choice to use with your virtual machines. One of those benefits is the ability to take snapshots of your virtual disks. In this post, I will show you how to take snapshots of your managed disks and how to create a VM using these snapshots.

Requirements:

  • This tutorial assumes that you already have a Microsoft Azure account set up.
  • You have an existing virtual machine that uses managed disks. If you want to know how to convert Azure VM to use Managed Disks, see this link.

Important: Snapshots are billed based on the used size.

Azure PowerShell Workaround

If you want to know how to install the PowerShell Azure module on your machine, check out this link.

The simplest way to get started is to sign in interactively at the command line.

This cmdlet will bring up a dialog box prompting you for your email address and password associated with your Azure account.
If you have more than one subscription associated with your mail account, you can choose the default subscription. To perform this task, we will use the following commands:

Create a snapshot

Set the variables
Here, we define the characteristics of our environment

Get the virtual machine

To get and store the virtual machine in a variable, use Get-AzVM with the following syntax.

Set the snapshot configuration

To set snapshot settings for an OS Disk, you should use New-AzSnapshotConfig cmdlet with the following syntax.

Depending on the value established in the -SKU parameters you can store your snapshot in

  • Standard_LRS
  • Standard_ZRS
  • Premium_LRS

if instead, you want to set snapshot settings for a Data disk, you should use the following syntax.

You must keep in mind the number of disks attached to your virtual machine to set the index. In my case, I only have a Data disk attached to the VM.

Take the snapshot

To take a snapshot, you should use the New-AzSnapshot cmdlet with the following syntax. In the following example, I set the name of the snapshots by adding the date to the name of the VM, but you can choose the name you want for your snapshots.,

New-AzSnapshot

Create an incremental snapshot

Microsoft has recently released the ability to take incremental snapshots of your managed disks. These types of snapshots include only all changes since the last snapshot. To use this type of snapshot follows the next steps.

You must first get the disk you have snapshots of and want to take an incremental snapshot. To do this you should use the cmdlet with the following syntax.

Set the snapshot configuration

To create an incremental snapshot, you should use the New-AzSnapShotConfig cmdlet with the new parameter -Incremental

Unlike regular snapshots, these types of snapshots are always stored on standard HDDs, regardless of the type of storage on the primary disks. Also, for increased reliability, they are stored in Zone Redundant Storage (ZRS) by default in regions that support ZRS.

Take the incremental snapshot

To take a snapshot, you should use the New-AzSnapshot cmdlet with the following syntax. In the following example, I set the name of the snapshots by adding the date to the name of the VM, but you can choose the name you want for your snapshots.

New-AzSnapshot

Create a VM from an existing snapshot

Here I will show you how to create a virtual machine from an existing snapshot taken from an OS disk.

Use the Get-AzSnapshot cmdlet, to list all available snapshots within the resource group is obtained.

Snapshots Managed disks

Once the snapshot is identified, the snapshot needs to be converted to a virtual disk. To do this you should use the following commands.

Then you should set the characteristics of the new VM. In my case, I use the original VM as a reference.

Here we set the size of the new virtual machine and disable boot diagnostics.

We use the Resource ID of the new managed disk to attach it to the virtual machine. In the last parameter, you can change the type of operating system to Linux if the operating system disk has Linux OS

select and store in the variable $vnet, the virtual network where the virtual machine will be hosted.

We create and add a network interface to the configuration of the new virtual machine.

and finally, we create a virtual machine with the established configuration.

New-AzVM

Another possibility to access the data stored in the snapshots is to convert the snapshots to virtual hard disks and then mount them as data disks in another VM.

Thanks for reading my post. I hope you find it useful.

If you want to know more about Azure Managed Disks, check out this link:https://docs.microsoft.com/en-us/azure/virtual-machines/windows/managed-disks-overview