Back up Azure unmanaged VM disks with incremental snapshots
Azure Storage provides the capability to take snapshots of blobs. Snapshots capture the blob state at that point in time. In this article, we describe a scenario in which you can maintain backups of virtual machine disks using snapshots. You can use this methodology when you choose not to use Azure Backup and Recovery Service, and wish to create a custom backup strategy for your virtual machine disks.
Azure virtual machine disks are stored as page blobs in Azure Storage. Since we are describing a backup strategy for virtual machine disks in this article, we refer to snapshots in the context of page blobs. To learn more about snapshots, refer to Creating a Snapshot of a Blob.
What is a snapshot?
A blob snapshot is a read-only version of a blob that is captured at a point in time. Once a snapshot has been created, it can be read, copied, or deleted, but not modified. Snapshots provide a way to back up a blob as it appears at a moment in time. Until REST version 2015-04-05, you had the ability to copy full snapshots. With the REST version 2015-07-08 and above, you can also copy incremental snapshots.
Full snapshot copy
Snapshots can be copied to another storage account as a blob to keep backups of the base blob. You can also copy a snapshot over its base blob, which is like restoring the blob to an earlier version. When a snapshot is copied from one storage account to another, it occupies the same space as the base page blob. Therefore, copying whole snapshots from one storage account to another is slow and consumes much space in the target storage account.
If you copy the base blob to another destination, the snapshots of the blob are not copied along with it. Similarly, if you overwrite a base blob with a copy, snapshots associated with the base blob are not affected and stay intact under the base blob name.
Back up disks using snapshots
As a backup strategy for your virtual machine disks, you can take periodic snapshots of the disk or page blob, and copy them to another storage account using tools like Copy Blob operation or AzCopy. You can copy a snapshot to a destination page blob with a different name. The resulting destination page blob is a writeable page blob and not a snapshot. Later in this article, we describe steps to take backups of virtual machine disks using snapshots.
Restore disks using snapshots
When it is time to restore your disk to a stable version that was previously captured in one of the backup snapshots, you can copy a snapshot over the base page blob. After the snapshot is promoted to the base page blob, the snapshot remains, but its source is overwritten with a copy that can be both read and written. Later in this article we describe steps to restore a previous version of your disk from its snapshot.
Implementing full snapshot copy
You can implement a full snapshot copy by doing the following,
- First, take a snapshot of the base blob using the Snapshot Blob operation.
- Then, copy the snapshot to a target storage account using Copy Blob.
- Repeat this process to maintain backup copies of your base blob.
Incremental snapshot copy
The new feature in the GetPageRanges API provides a much better way to back up the snapshots of your page blobs or disks. The API returns the list of changes between the base blob and the snapshots, which reduces the amount of storage space used on the backup account. The API supports page blobs on Premium Storage as well as Standard Storage. Using this API, you can build faster and more efficient backup solutions for Azure VMs. This API will be available with the REST version 2015-07-08 and higher.
Incremental Snapshot Copy allows you to copy from one storage account to another the difference between,
- Base blob and its Snapshot OR
- Any two snapshots of the base blob
Provided the following conditions are met,
- The blob was created on Jan-1-2016 or later.
- The blob was not overwritten with PutPage or Copy Blob between two snapshots.
Note: This feature is available for Premium and Standard Azure Page Blobs.
When you have a custom backup strategy using snapshots, copying the snapshots from one storage account to another can be slow and can consume much storage space. Instead of copying the entire snapshot to a backup storage account, you can write the difference between consecutive snapshots to a backup page blob. This way, the time to copy and the space to store backups is substantially reduced.
Implementing Incremental Snapshot Copy
You can implement incremental snapshot copy by doing the following,
- Take a snapshot of the base blob using Snapshot Blob.
- Copy the snapshot to the target backup storage account using Copy Blob. This is the backup page blob. Take a snapshot of the backup page blob and store it in the backup account.
- Take another snapshot of the base blob using Snapshot Blob.
- Get the difference between the first and second snapshots of the base blob using GetPageRanges. Use the new parameter prevsnapshot, to specify the DateTime value of the snapshot you want to get the difference with. When this parameter is present, the REST response includes only the pages that were changed between target snapshot and previous snapshot including clear pages.
- Use PutPage to apply these changes to the backup page blob.
- Finally, take a snapshot of the backup page blob and store it in the backup storage account.
In the next section, we will describe in more detail how you can maintain backups of disks using Incremental Snapshot Copy
In this section, we describe a scenario that involves a custom backup strategy for virtual machine disks using snapshots.
Consider a DS-series Azure VM with a premium storage P30 disk attached. The P30 disk called mypremiumdisk is stored in a premium storage account called mypremiumaccount. A standard storage account called mybackupstdaccount is used for storing the backup of mypremiumdisk. We would like to keep a snapshot of mypremiumdisk every 12 hours.
To learn about creating storage account and disks, refer to About Azure storage accounts.
To learn about backing up Azure VMs, refer to Plan Azure VM backups.
Steps to maintain backups of a disk using incremental snapshots
The following steps describe how to take snapshots of mypremiumdisk and maintain the backups in mybackupstdaccount. The backup is a standard page blob called mybackupstdpageblob. The backup page blob always reflects the same state as the last snapshot of mypremiumdisk.
- Create the backup page blob for your premium storage disk, by taking a snapshot of mypremiumdisk called mypremiumdisk_ss1.
- Copy this snapshot to mybackupstdaccount as a page blob called mybackupstdpageblob.
- Take a snapshot of mybackupstdpageblob called mybackupstdpageblob_ss1, using Snapshot Blob and store it in mybackupstdaccount.
- During the backup window, create another snapshot of mypremiumdisk, say mypremiumdisk_ss2, and store it in mypremiumaccount.
- Get the incremental changes between the two snapshots, mypremiumdisk_ss2 and mypremiumdisk_ss1, using GetPageRanges on mypremiumdisk_ss2 with the prevsnapshot parameter set to the timestamp of mypremiumdisk_ss1. Write these incremental changes to the backup page blob mybackupstdpageblob in mybackupstdaccount. If there are deleted ranges in the incremental changes, they must be cleared from the backup page blob. Use PutPage to write incremental changes to the backup page blob.
- Take a snapshot of the backup page blob mybackupstdpageblob, called mybackupstdpageblob_ss2. Delete the previous snapshot mypremiumdisk_ss1 from premium storage account.
- Repeat steps 4-6 every backup window. In this way, you can maintain backups of mypremiumdisk in a standard storage account.
Steps to restore a disk from snapshots
The following steps, describe how to restore the premium disk, mypremiumdisk to an earlier snapshot from the backup storage account mybackupstdaccount.
- Identify the point in time that you wish to restore the premium disk to. Let's say that it is snapshot mybackupstdpageblob_ss2, which is stored in the backup storage account mybackupstdaccount.
- In mybackupstdaccount, promote the snapshot mybackupstdpageblob_ss2 as the new backup base page blob mybackupstdpageblobrestored.
- Take a snapshot of this restored backup page blob, called mybackupstdpageblobrestored_ss1.
- Copy the restored page blob mybackupstdpageblobrestored from mybackupstdaccount to mypremiumaccount as the new premium disk mypremiumdiskrestored.
- Take a snapshot of mypremiumdiskrestored, called mypremiumdiskrestored_ss1 for making future incremental backups.
- Point the DS series VM to the restored disk mypremiumdiskrestored and detach the old mypremiumdisk from the VM.
- Begin the Backup process described in previous section for the restored disk mypremiumdiskrestored, using the mybackupstdpageblobrestored as the backup page blob.
Use the following links to learn more about creating snapshots of a blob and planning your VM backup infrastructure.