Snapshots are a fantastic tool, but Hyper-V will require you to perform some minor maintenance. It isn’t difficult work at all, but you do need to be aware of it.
Snapshots are one of the most overlooked gifts of virtualization. If you’re about to do something risky to a virtual machine, such as installing a Windows Service Pack, take a snapshot of it first; if anything at all goes wrong, only a few moments are required to restore the server to the exact state it was in when you took the snapshot.
Sound Great – Too Great, Actually
Snapshotting is a terrific technology, but avoid over-usage. It is has drawbacks and is absolutely not a replacement, or even a stand-in, for backup. It is intended for short-term operations, as mentioned above. The primary reason is that restoring a snapshot is an all-or-nothing operation; you cannot selectively restore parts or “restore over the top” as you could with a backup. Restoring a snapshot brings the machine back to the exact state it was in when the snapshot was taken, with no exceptions. This means that the longer it’s been since the snapshot was taken, the less useful it is.
It is possible to have multiple snapshots. You can take a current snapshot and then restore to an earlier snapshot; this technique can be used to structure snapshot trees. Activities such as these lead right into the second problem with snapshots: the amount of hard drive space they consume can be significant. This will be explored in more depth in the next part.
What is Snapshotting, Really?
The mechanics of snapshotting are pretty simplistic. You issue the command to take a snapshot (called “checkpoints” in SCVMM for whatever reason). The hypervisor creates a differencing disk (.AVHD) and stops writing to the .VHD. Writes go to the differencing disk. Reads are run from the newest version (performance impact while it sorts out what data it wants). The configuration and memory state at the time of snapshot are also stored, and any changes are kept separate. When you revert to a snapshot, that [A]VHD file and its related configuration/memory files become active for the VM and it resumes operation as it was at that point. Tracking the differences can cause a substantial amount of disk space to be used, so definitely be judicious about snapshotting high-activity VMs and delete the snapshots as soon as they are no longer necessary.
One of the drawbacks of Hyper-V’s snapshotting mechanism is that it doesn’t do any clean-up work while the VM is powered on. AVHD files live pretty much forever if the VM is left powered on, even when you’ve used the tools to delete the snapshots. Removing all snapshots that are parents of the current state will cause the system to stop tracking changes, which will in turn allow performance and AVHD growth to return to normal, but Hyper-V will continue using the AVHD file.
Maintenance is automatic – when you turn off the VM. It isn’t instantaneous, however, as Hyper-V has to merge the VHD and its associated AVHD(s). Simply telling the VM to reboot won’t work, as the VM needs to be powered off while the changes are merged. If the VM is turned back on before the merge completes, the AVHD file remains.
To monitor progress, you must use Hyper-V Manager. SCVMM can’t track progress of a merge. Delete any snapshots that you don’t want, then shut the VM down normally. Hyper-V Manager will show “Merge in progress” in the Status column for the VM. Once that’s complete, all the AVHD files will be gone.
Absolutely never use snapshots on a domain controller.
Absolutely never use any defragmenting tool on a machine with snapshots.
Before reverting to a snapshot, take another snapshot.
It can’t be said enough: snapshot is not a replacement for backup.
Snapshots can get out of control and consume 100% of available disk space, which has another side effect of making it impossible for Hyper-V to merge the snapshots back into the VHD. Use Hyper-V to export the VM to another location; it will go without any AVHDs (unless you still have active snapshots). You can then delete the VM’s remnants and reimport the VM.
Hyper-V Manager allows you to re-target the snapshot location for an individual VM. Open the settings dialog on a VM and the “Snapshot File Location” tab is near the bottom. There is no way to change the location for all guests at once or for newly created guests going forward. If you have a VM that you expect to see a large amount of snapshot utilization, you can use this setting to ensure it doesn’t cripple a populous CSV and has room to grow.