Taking VHD snapshot with Windows Azure Virtual Machines

One very useful capability of virtualisation (in general) is the ability to take snapshots of a disk at a point in time, allowing restoring the machine to a known state quickly and easily.

With Windows Azure Virtual Machines one does not have access to the hypervisor (for obvious reasons!), so could this be achieved?

The answer is – by taking a snapshot of the underlying blob on which the VHD is stored.

To demonstrate I’ve created a brand new Machine from the galley – I’ve used the SQL template-

image

I then went ahead and created a quick database and added several rows to it through the SQL Management Console -

image

At this point, using Cerebrata’s Cloud Storage Studio in my case, I took a snapshot of the blob containing the VHD

image

With the snapshot taken I went ahead and removed the table, only to create a new one with slightly different structure and values, to make sure the state of the machine had changed since I took the snapshot -

image

Now I wanted to restore it to it’s previous state.

I could chose to do that to a brand new machine or to override the existing machine, the later would of course require that I first remove the machine (and disk) from the management portal so that the lease on the underlying blob would be returned making it writable, and that’s what I’ve done. If I wanted to create a new machine I would have used the CopyBlob capability to copy the snapshot to a new blob, making it writable (snapshots are read only), and then create a disk and machine out of that, next to my existing machine.

In my case I wen on to delete the Virtual Machine and the related disk and, using Storage Studio again in my case, I ‘promoted’ the snapshot – tthis simply copies the snapshot back to the original blob.

image

With this done, I now have the older snapshot as the current blob, and it was time to re-create the disk..

image

…and virtual machine -

image

image

..and sure enough, once the machine finished started I connected to it and looked at the databases using SQL Management studio again, which contained the original database and values, as expected -

image

Quick update – I have added a post about how to do this from PowerShell, read it here

About these ads

About Yossi Dahan
I work as a principal consultant in the CTO office of Solidsoft - a Microsoft partner in the UK with a strong focus on cloud, hybrid and integration based solutions. I spend my days working with both our customers and our project teams, helping them explore the possibilities that technology enables and how to derive value from them.

8 Responses to Taking VHD snapshot with Windows Azure Virtual Machines

  1. Pingback: Czech MSDN Blog

  2. Pingback: Kačiho platformový blog

  3. Paul Stubbs says:

    Good post. Be careful in how you think about this scenario. Snapshotting usually implies capturing the disk state and the memory state; which is not the case here as we can only capture a copy of the VHD file at that point in time in a running state. Which means that when you reattach to another VM it will boot up as if you had pulled the plug on the machine. Most of the time this is ok, just be aware that this may not be ok for all applications and probably has edge cases where this could be flaky. Also you should consider how you will restore the VM. I would recommend using the PowerShell Export and Import feature as it will capture the networking and endpoint information as well. And finally also take into consideration if your App consists of more than 1 VM. For example maybe you are using DataDisks. So you want to be sure to capture all of these at the same time as well. I am pushing the product team to add real snapshotting capabilities in the future, for now in V1 you will need to take a different approach.

  4. Luis Panzano says:

    Hi Paul,

    I think you are right. You should shut down the machine before doing the snapshot and then you are safe. If you export also the VM state with Export-AzureVM command, you will have all you need in case you want to restore the VM in another datacenter for example.

  5. Loc Smith says:

    Yossi,

    Why is there no native tool within Windows Azure platform to backup/restore a VM?
    I know the sites are replicated to different locations, but that does not help if a VM gets corrupted.
    Do you recommend a 3rd party provider that can backup/restore a VM without needing to jump hoops?

    Thanks!

  6. Jagdish says:

    When I delete the VHD as mentioned it dissapears from Azure Management studio and there is no option to promote a snapshot.
    If i do not delete the VHD, it does not allow me to promote a snapshot as the lease is existing.

  7. Same for me. Downloaded Azure Explorer. There is an option Break Lease on Blob.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 28 other followers

%d bloggers like this: