Taking VHD snapshot with Windows Azure Virtual Machines
June 15, 2012 6 Comments
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-
I then went ahead and created a quick database and added several rows to it through the SQL Management Console -
At this point, using Cerebrata’s Cloud Storage Studio in my case, I took a snapshot of the blob containing the VHD
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 -
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.
With this done, I now have the older snapshot as the current blob, and it was time to re-create the disk..
…and virtual machine -
..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 -
Quick update – I have added a post about how to do this from PowerShell, read it here
Pingback: Czech MSDN Blog
Pingback: Kačiho platformový blog
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.
Thank you Paul for the very good additions.
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.
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!