Snapshots are a storage function that allows an administrator to create a restore point of a virtual machine's operating system, applications, and data at a certain point in time. Snapshots save the data currently present in a virtual machine hard disk images as a read only volume and allow for a recovery to the data as it existed at the time the snapshot was taken. A snapshot causes a new COW layer to be created over the current layer. The layer in use before the snapshot becomes read-only and all write actions performed after a snapshot is taken are written to the new COW layer.
It is important to understand that a virtual machine hard disk image is a chain of one or more volumes. From the perspective of a virtual machine, these volumes appear as a single disk image. A virtual machine is oblivious to the fact that its disk is comprised of multiple volumes.
The term COW volume and COW layer are used interchangeably, however, layer more clearly recognizes the temporal nature of snapshots. Each snapshot is created to allow an administrator to discard unsatisfactory changes made to data after the snapshot is taken. Snapshots also to preserve the data present before the snapshot is taken. Snapshots provide similar functionality to the Undo function present in many word processors.
Snapshots within the Red Hat Enterprise Virtualization environment cause new
Copy On Write (
COW) layers to be created for changes made to a virtual machine disk image after a snapshot is taken. The initial snapshot causes any existing volumes to be marked read only. These can be either COW or RAW. From that point on, all changes and new data are written to a new, COW layer until another snapshot is taken.
The three primary snapshot operations are:
Snapshot creation, which involves the first snapshot created for a virtual machine.
Snapshot Previews, which involves previewing a snapshot to determine whether or not to restore the system data to the point in time that the snapshot was taken.
Snapshot deletion, which involves deleting a restoration point that is no longer required.
For task based information about snapshot operations, refer to the
Red Hat Enterprise Virtualization Administration Guide.
In Red Hat Enterprise Virtualization the initial snapshot for a virtual machine is different from subsequent snapshots in that the initial snapshot retains its format, either QCOW2 or RAW. The first snapshot for a virtual machine designates existing volumes as a read-only base image. Additional snapshots are additional COW layers tracking the changes made to the data stored in the image since the previous snapshot.
In Red Hat Enterprise Virtualization, a guest virtual machine usually interacts with a RAW disk image unless the image is created as a thinly provisioned image or the user specifically asked for it to be QCOW2. As depicted in
Figure 3.5, “Initial Snapshot Creation”, the creation of a snapshot causes the volumes that comprise a virtual machine disk image to be marked as read only and serve as the base image for all subsequent snapshots.
Each new snapshot causes the COW layer currently in use for virtual machine write operations to be marked read only.
Snapshots taken after the initial snapshot result in the creation of new COW volumes in which data that is created or changed after the snapshot is taken will be stored. Each new COW layer begins containing only COW metadata. Data that is created through virtual machine use and operation after a snapshot is written to a new COW layer. When a virtual machine is used to modify data that exists in a previous, read only COW layer, the data is read from the read only layer, and written into the newest, writable COW layer. Virtual machines locate data by checking each COW layer from most recent to oldest, transparently to the virtual machine.
Red Hat Enterprise Virtualization requires a virtual machine to be shut down before a snapshot of it is created.
To select which snapshot a virtual machine disk image will be reverted to, the administrator can preview all previously created snapshots.
From the available snapshots per guest, the administrator can select a snapshot volume to preview its contents. As depicted in
Figure 3.7, “Preview Snapshot”, each snapshot is saved as a COW volume, and when it is previewed, a new preview layer is copied from the snapshot being previewed. The guest interacts with the preview instead of the actual snapshot volume.
After the administrator previews the selected snapshot, the preview can be committed to restore the guest data to the state captured in the snapshot. If the administrator commits the preview, the guest is attached to the preview layer.
After a snapshot is previewed, the administrator can select to discard the preview layer of the viewed snapshot. The layer that contains the snapshot itself is preserved despite the preview layer being discarded.
If a snapshot or series of snapshots are no longer required, the administrator can delete one or more snapshots. The deletion of a snapshot does not necessarily cause the data in the snapshot to be deleted. For example, if the third snapshot out of five snapshots is deleted, the unchanged data in the third snapshot must be preserved for the fourth and fifth snapshots to be usable. If the fifth snapshot out of five is deleted, then the data that has been modified or created since the snapshot was taken will be discarded. Snapshot deletion is not an operation to preserve storage capacity within the Red Hat Enterprise Virtualization environment. Snapshot deletion allows an administrator to remove a potential data restoration point when it becomes clear that it will not be necessary to return a virtual machine hard disk image data to the point in time the snapshot preserves.
When the administrator deletes a snapshot, the data from the deleted snapshot and the snapshot created after the deleted snapshot are merged into a single COW volume. After the two snapshots are merged, the resultant volume contains any data that was created or modified prior to the deleted snapshot and after the deleted snapshot. No data has been removed, only the ability to restore a point in time in the life of the virtual machine hard disk image. As displayed in
Figure 3.8, “Snapshot Deletion”, snapshot 2 is selected for deletion. As a consequence, snapshot 2 and snapshot 3 are merged, saving the changes in both snapshots in the COW volume for snapshot 3 (i.e. the newer snapshot) as the replacement for the deleted snapshot.