Step-By-Step: Creating a VM Snapshot in Azure

As you may know, I’ve been travelling around the country for the Cloud and Mobility Summit. During these events we’ve been running day long “camps” or hands-on training for both “Getting Started with Microsoft Azure for IT Professionals” and “Getting Started with Identity Management & Business Mobility Enablement for IT Professionals”

During these camps a lot of questions/scenarios are discussed. Today I wanted to cover snapshots in Azure since its a topic that keeps coming back.

VM Snapshots

First, let me go on record to say that I'm not a huge fan of Snapshots. Not because they don't serve a propose, but because they are regularly used as a proper backup replacement. We’ll discuss VM backups in a upcoming post. but for now let’s just keep it to VM snapshots.

In Azure we’re not taking a snapshot the same way we take snapshots/checkpoints in Hyper-v. In Azure, a blob snapshot is a read-only version of a blob that's taken 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 that moment in time.

A snapshot of a blob has the same name as the base blob from which the snapshot is taken, with a DateTime value appended to indicate the time at which the snapshot was taken. For example, if the page blob URI is http://storagesample.core.blob.windows.net/mydrives/myvhd, the snapshot URI will be similar to http://storagesample.core.blob.windows.net/mydrives/myvhd?snapshot=2011-03-09T01:42:34.9360000Z. This value may be used to reference the snapshot for further operations. A blob's snapshots share its URI and are distinguished only by this DateTime value

Creating a VM Snapshot

For the creation of a VM blob snapshot we’ll use a PowerShell script created by a friend of mine, Chris Clayton. You can download it here. Once downloaded you need to expand it to a local directory and you will have the following structure and files.

Before you go and run any scripts there are a few things to take care off.

1- Ensure you have the latest Windows Azure PowerShell Module. You can follow the step outlined here.

2- You need to download and import the certificate using the following PowerShell command. Get-AzurePublishSettingsFile and Import-AzurePublishSettingsFile

3-You need to edit the Subscription.CSV file to include the following:

SubscriptionName

SubscriptionId

CertificateThumbprint

the SubscriptionName (1) and the SubscriptionId (2) can be found in the Settings tab of the Azure portal

And the CertificateThumbprint (3) can be found under Settings>Management certificates.

3- Now that the info is in a place where the script can get to it, we will run the SnapshotVirtualMachine.ps1 script to capture the Blob snapshot. (the command should be on one line. It’s has been formatted to fit this page.)

You’ll notice that the command includes –shutdownMachine . It is recommended that you shutdown the VM to perform the snapshot. Mostly because this is a storage function of Azure not a hypervisor function.

if everything goes well, you’ll get the following display.

Managing Snapshots

The script ZIP file you downloaded contained several other scripts to allow you to manage your snapshots: