Thursday, January 1, 2009

Hyper-V Snapshots


Our servers are now moved over to a Hyper-V virtualised environment, but not without difficulties. The first thing to note about Hyper-V is that there is a really useful snapshot tool which you think is a wonderful backup tool, but actually is far from the truth.

In our environment we use .VHD files to contain the Hyper-V images which are used by the guest Virtual Machines. Now these .VHD in essence contain all your servers operating system, settings and of course data.

With a simple right click in Hyper-V manager you can create a snapshot of your virtual machine, which you would think just creates a snapshot allowing you to revert back to that snapshot in the event of a failure. However what it does not tell you is as soon as you create a snapshot the original .VHD file you think all your data is in stops being written to. Instead a .AVHD file is created with a hidden folder c:\ProgramData\Microsoft\Windows\Hyper-V\GUID Number.

Now this is all well and good if you know this is happening, but if you created the snapshot a few days ago and then made a lot of changes to your server or indeed added loads of data as I did, having this all in the .AVHD rather than the .VHD can cause some major problems, especially as only the .VHD was being backed up! the only way to get the snapshots to merge back in with the original .VHD is to delete the snapshot (working backwards with the last snapshot created first), and then shutdown the Virtual Machine, the changes are then merged back in - a warning here though this process can take hours, and if you have many snapshots, it can take many hours.

So a lesson learnt, If you do use snapshots for example prior to installing a service pack which is good recommended practice, then please delete them once you have tested the change has been good and commit the changes back immediately but shutting down the VM.


2 comments:

Scotty P said...

Hind site ... oi. Thanks for the info. We have 1 VM that ran out of disk space (I noticed this because the VM stops when there's not enough disk space around) and I concluded that removing the snapshots would solve the issue ... I couldn't delete the files because they were 'in use'. I thought shutting down the server would allow me to remove them ... and then Merging in Progress started ...

Gary said...

... Yes, its a bit of a nightmare the merging state process, and no warning that this is going to take place. It would be great if Microsoft took some action to warn before shutdown that a merge would take place so that at least you could plan or prepare for it.