Have you ever wished you could go back in time and remember how your virtual machines (VMs) used to look? You know,...
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
like before you installed that pre-production beta patch on a mission-critical application? Or before you accidentally overwrote the passwords in a login table by leaving off the WHERE clause of an SQL UPDATE statement?
As the father of more VMs than I can count, I often feel the same way. Fortunately, Microsoft's Hyper-V provides a useful method of creating and applying point-in-time views of the status of your VMs: the aptly-titled snapshots feature. This easy-to-use tool can create VM snapshots from the Hyper-V Management Console.
Introduction to Hyper-V snapshots
In order to record the complete state of a virtual machine, you need many different pieces of information. While it is possible to backup all the necessary files and settings manually, the process can be a tedious and error-prone one. A Hyper-V snapshot includes all of the information and data that is required to roll back the status of a VM to a previous point-in-time. This includes:
- Virtual Machine configuration settings (the contents of the .vmc file)
- Virtual network settings
- The current state of all virtual hard disks (VHDs) that are attached to the VM
- Saved state information for the VM (if applicable)
Best of all, you don't need to do anything special to enable snapshots. As long as you have a Hyper-V VM, you can use this feature.
Creating a VM scrapbook with snapshots
Creating a snapshot can be done while a VM is "hot": Usually the process takes only a few seconds and does not require the VM to be paused, stopped or powered off. Snapshots are created and performed by Hyper-V and are completely independent of the type and capabilities of the Guest OS that is running within a child partition. Snapshot-related files are stored automatically, based on the default paths defined in the Hyper-V server settings.
You can easily create a snapshot in the Hyper-V Management console by right-clicking a VM and choosing Create Snapshot. Snapshots can be created at any time and are automatically nested into a hierarchy of point-in-time views of each VM (see Figure 1). You can access details for a snapshot by viewing its properties. The settings stored in snapshots are read-only, unless or until you apply them to the existing VM.
Figure 1: Viewing snapshots for a VM using the Hyper-V Management Console
Note that Hyper-V snapshots are independent of file system snapshots, such as those that are generated by Microsoft's Volume Shadow Services (VSS) feature. The technologies might share the same terminology, but Hyper-V snapshots do not rely on file system snapshot features.
Snapshots and undo disks
Snapshots largely replace the concept of "undo disks" in Microsoft Virtual PC and Microsoft Virtual Server. Before Hyper-V, you would enable undo disks before you booted a VM. Then, when the VM was stopped or powered off, you could decide whether you wanted to keep the saved state, commit the changes permanently or discard the changes altogether.
Snapshots in Hyper-V provide the same capabilities but with different terminology and operations. The primary benefit of Hyper-V's model is that it allows administrators to quickly and easily create hierarchies of changes and to revert back to them at any time. Furthermore, it addresses the potential problems associated with VM configuration changes (for example, if virtual network or memory settings were changed) and with VMs that have multiple VHDs.
When you apply a snapshot, the current configuration of the VM will be completely overwritten. Keep in mind that this includes the contents of all of the attached virtual hard disks. Because the process is permanent, it's a good idea to create a new snapshot just prior to applying an older one. This will give you a way to roll-back from the roll-back operation. Additionally, the VM will be placed in a powered-off state if the VM was originally off or in saved state if the VM was originally powered on. When you revert to a snapshot, any other snapshots that were dependent on it will also be removed because they are no longer valid.
Transferring Snapshots: Importing and Exporting VMs
Like an important photo album that includes baby pictures, you'll probably want to take your VM snapshots with you whenever you move the VM itself. The easiest way to do this is use Hyper-V's Export command. You can then use the Import command on the destination server to restore the VM and all related files and settings. Both operations can be performed using scripts or through the Hyper-V Management Console.
Best practices for Hyper-V snapshots
In general, you should create snapshots of VMs immediately prior to making any type of change that involves risk. For example, if you're applying updates or patches to the OS and want the ability to easily undo them, create a snapshot before you make the change. The same applies to when you're making changes to configuration settings for the VM or for critical guest OS services.
Snapshots are not always appropriate in every situation. First and foremost, snapshots are not a replacement for backups. You should still adhere to best practices related to backing up VMs (manually with scripts or using virtualization-aware tools). And be sure to take advantage of guest OS features wherever relevant. For example, if you're about to make a critical database change, create a standard database backup from within the VM. Keep in mind that some types of applications and services might not take too kindly to being thrown back in the past. Microsoft's Active Directory is one that comes to mind. This replicated database relies on timestamps and serial change logs in order to reconcile changes.
Still, snapshots are truly worth a 1,000 words (or several hundred megabytes) if used correctly.
Snapshots in Hyper-V are convenient, always available, and simple to create and apply. Much like a digital camera, the behind-the-scenes technology can be somewhat complicated to understand. However, you'll be glad you created point-in-time images of your VMs the next time you might accidentally run a recursive script to delete temporary files and start at the root of your C: volume.
About the author: Anil Desai is a Microsoft MVP and a Microsoft Certified Professional with numerous credentials including MCITP, MCSE, MCSD, and MCDBA. He is the author or coauthor of nearly 20 technical books, including several study guides for Microsoft Certifications.