It’s sometimes quite difficult to talk and think at the same time, and at our camps last week I think we may have caused some confusion around snapshots for virtual machines (VM) that are in production so I wanted to write this up from first principles so that I have somewhere to refer to in future.
All server virtualisation vendors have a way of creating a file that represents a physical hard disk – a virtual hard disk. In Hyper-V in Windows Server this is referred to as a “VHD” and currently has a .VHD extension limited to 2Tb in size. In Hyper-V in Windows Server 2012 you can use this version of VHD so your existing VMs will work, but there is also the newer VHDX format which goes up to 64TB.
VHDs come in three flavours:
Fixed. You declare their size and this space is reserved at creation time. This is the fastest VHD as there is no overhead in growing the disk and if the VHD is created on a well optimised physical disk it will reside on contiguous blocks as well. You can expand these disks later if needed, but remember you will also need to go into the VHD and extend the volumes on it to get the operating system to use it as well
Dynamic. As the name suggests these expand as required, and in fact they are tiny to begin with no matter what size you declare. There is a background process to expand them as needed so the guest operating system is never aware that the specified maximum size isn’t really there yet. However there may come a moment when the physical disk may run out of space in which case your VMN will stop gracefully until this is resolved.
Differencing. In this scenario you have a parent VHD from which you create a new child VHD into which any changed data goes. For example my parent VHD might have a sysprepped Windows Server installation on and then as the VM comes up for the first time all the changes get written in to the child VHD, the parent never changes. This is important as you can then create another child form the same parent to create another windows server VM. This saves me loads of disk space on my demo rig, but the performance is not as high as it would be for a fixed disk and the savings in disk decline over time as each child VM would need to patched and service packed, as the parent cannot be changed. Differencing disk really come into their own for Virtual Desktop infrastructure where you have lots of windows 7 VMs that are little different form each other.Note also the at a differencing disks themselves can
I mention this because taking a checkpoint/ snapshot of a VM is like using a parent disk – all the changes to a VM after a snapshot is taken are written to a new VHD (You’ll see this on your physical disks with a .AVHD extension where you specified to save your snaphots). If I create a subsequent snapshot then another AVHD is created and changes are then written to this newer AVHD file. If I delete a snapshot on a VM running in Hyper-V in Windows Server 2008 R2 nothing really happens until the VM is stopped and restarted. At that time the data in the AVHD is merged into the parent be that an earlier AVHD representing a snapshot or the actual VHD itself. In other words you wont get the disk space back from a snapshot until reboot and moreover Hyper-V needs some additional disk space to do this merging. This changes in Windows Server 2012 in that merging will occur as soon as you delete the snapshot i.e. whether the VM is running or not.
So having understood all of that what about snapshots in production? Yes definitely as a fall back for applying changes to production but NOT as a backup or your only DR solution for mission critical services, which was the point Simon and I were trying to make at the IT Camp. For one thing you may have a multi-tier service that will respond well to rolling back one of its constituent VMs or there might be time sensitive code in there that will be confused when you revert to a snapshot. Also having a disk with snapshots in is slower than a fixed disk so there might be performance considerations until you can restart the VM and remove the snapshot. As I say this last problem goes away in Windows Server 2012 as snapshots get deleted while the VM is running, so you only have to retain a snapshot until you are sure the change you have made is working as expected.