NAKIVO Blog

VMware Snapshots in vSphere How To

VMware vSphere virtual machines provide powerful capabilities that allow today’s workloads to have a very agile, versatile, and efficient environment for software. One of the tantalizingly cool features of VMware virtual machines since they came on the scene has been the ability to take snapshots and revert back to those snapshots if need be. Snapshots provide very specific use cases that can be leveraged in certain situations. Let’s take a deeper look into the anatomy of VMware snapshots. What are VMware snapshots? What are acceptable use cases for snapshots? How do we go about creating snapshots both in vSphere web client as well as via PowerCLI?

What are VMware Snapshots?

A VMware snapshot is a point in time version of a particular virtual machine. Many might think of a VMware snapshot as an image and we may have heard them called that. However, images in the legacy use of the term are simply representations of the files that reside on a disk. VMware snapshots are more than that, however, as they have the mechanism built in to preserve not only the data of a virtual machine but also the state of that virtual machine. When we think about the state of a virtual machine, this includes not simply the data as mentioned but the memory footprint at the time of the snapshot which allows the capturing of the power state of the virtual machine. Aside from the disk and memory contents included in a snapshot, the VMware snapshot also includes the configuration of the virtual machine itself including devices, virtual network cards, etc. For instance, you could take a snapshot of a virtual machine without a secondary virtual NIC. Then if you add a secondary NIC and then roll back to the snapshot, the NIC will be gone as it is very much a configuration snapshot as well as data and state.

Possible Use Cases for VMware Snapshots

Since a snapshot is a point in time version of a particular virtual machine including files, state, and configuration elements, wouldn’t this suffice to say that we have a backup of a virtual machine if it contains a snapshot? No. VMware snapshots are NOT backups of virtual machines. Many have mistakenly viewed them as such and were left in the lurch because of this mistaken use case. Snapshots are not backups as they are not independent of the virtual machine files themselves. In fact, they rely on the very virtual machine files that they may differ from. Snapshots can be known as differencing disks as they really are a set of delta information in relation to the “base” disk. They are sometimes referred to as snapshot “chains” due to this interrelationship between the child/delta disk and the base disks they depend on. If the base disks on which the snapshots depend are deleted, the snapshots do not contain the data needed to recreate the missing data. In contrast, backups are independent mechanisms that allow virtual machine files, disks, and entire virtual machine registrations to be recreated with no dependency on the production data or virtual disks contained in the virtual machine.

Since snapshots are not “backups” what are they good for exactly? Often snapshots are used for quick “rinse and repeat” type operations especially with development. A snapshot may be created before a certain software process is tested on a virtual machine. The virtual machine can then be quickly reverted back to the snapshot to bring the virtual machine back to the pristine condition it was in before running the software update, etc.

VMware does not support snapshots being run in production or long-term deployments of snapshots. They are not meant to be left in place for an extended length of time as they can lead to performance degradation or disk space issues if left unchecked.

What is the Anatomy of a Snapshot on Disk?

In VMware’s implementation of virtual machine snapshots, they are comprised of the following set of files that make up the snapshot file infrastructure.

A snapshot operation in VMware creates the following files:

  • .vmdk – This is the base virtual machine disk that contains the raw data.
  • -00000x.vmdk – The delta disk is represented in the format of -00000x.vmdk. This contains the difference between the current state of the virtual disk and the state of the virtual disk at the time the previous snapshot was taken.
  • .vmsd – This is the database file for the snapshot. It contains the snapshot information used by the snapshot manager. The database contains the relationships between snapshots and child disks for each snapshot.
  • .vmsn – This file includes the active state of the virtual machine including the memory. This allows you to revert to a running state of the virtual machine when reverted. A snapshot created without including the memory, reversion to the snapshot will be to a virtual machine that is powered off.
VMware Snapshots anatomy

Creating Snapshots

The following walkthrough is using the new HTML5 web client with vSphere 6.5 Update 1. Right-click the VM you want to create a snapshot on and select Snapshots >> Take Snapshot.

vSphere Client: Take Snapshot

In the Take Snapshot dialog, you can name the snapshot as well as create a description for the snapshot if you want to add more details. Note the checkbox for Snapshot the virtual machine’s memory that we can select. If we don’t check this box, reverting back to the snapshot will result in a powered off state. The virtual machine’s memory contains the relevant memory state information required to revert back in a powered on state.

Snapshot VM memory

Once we click OK to create the snapshot, we can see the relevant task kick off in the vCenter Recent Tasks pane.

vCenter Recent Tasks

After we create a snapshot, we can manage it by right-clicking and selecting Snapshots >. Manage Snapshots.

Manage snapshots

In the Manage Snapshots dialog, we can see the snapshots that exist on a virtual machine as well as the options to Delete All, Delete, and Revert To. Other pertinent information is displayed as well such as the Snapshot name, time created, and disk usage.

Manage Snapshots: TestSnap

Creating Snapshots using PowerCLI

A very powerful way to interact with vSphere is by using PowerCLI. PowerCLI can be used to create, delete, and revert snapshots. Let’s look at some basic syntax to do this.

Creating Snapshots with PowerCLI

To create a snapshot using PowerCLI we can use the following syntax:

  • get-vm testvm | new-snapshot -Memory -quiesce -name “Test snap”

Removing a snapshot

To remove a snapshot, we can store the snapshot name in a variable such as $snap and use it to remove the snapshot in question:

  • Remove-Snapshot -Snapshot $snap -RemoveChildren

Reverting to a snapshot

To revert to a snapshot that was created, we can use the following syntax:

  • get-vm “testvm” | set-vm -snapshot “Test snap” -confirm:$false

Concluding Thoughts

Snapshots provide a powerful mechanism to be able to revert back to a known state of a VMware virtual machine. This includes the files on disk, in memory, as well as configuration present on the virtual machine at the time the snapshot was created. Especially in development environments, the use of snapshots can be very beneficial when testing code integration, updates, or other modifications that may need more than one run through. By reverting back to a snapshot, you can quickly and efficiently get back to a known good state. However, snapshots are not backups and should only be present in development environments and not in production. Additionally, they shouldn’t be left on a virtual machine for long periods of time as they can lead to performance degradation and excessive disk space usage.