VM snapshots

XenServer provides a convenient mechanism that can take a snapshot of a VM storage and metadata at a given time. Where necessary, I/O is temporarily halted while the snapshot is being taken to ensure that a self-consistent disk image can be captured.

Snapshot operations result in a snapshot VM that is similar to a template. The VM snapshot contains all the storage information and VM configuration, including attached VIFs, allowing them to be exported and restored for backup purposes. Snapshots are supported on all storage types. However, for the LVM-based storage types the following requirements must be met:

  • If the storage repository was created on a previous version of XenServer, it must have been upgraded
  • The volume must be in the default format (you cannot take a snapshot of type=raw volumes)

The snapshot operation is a two-step process:

  • Capturing metadata as a template.

  • Creating a VDI snapshot of the disks.

Three types of VM snapshots are supported: regular, quiesced, and snapshot with memory

Regular snapshots

Regular snapshots are crash consistent and can be performed on all VM types, including Linux VMs.

Quiesced snapshots

Quiesced snapshots take advantage of the Windows Volume Shadow Copy Service (VSS) to generate application consistent point-in-time snapshots. The VSS framework helps VSS-aware applications (for example, Microsoft SQL Server) flush data to disk and prepare for the snapshot before it is taken.

Quiesced snapshots are therefore safer to restore, but can have a greater performance impact on a system while they are being taken. They may also fail under load so more than one attempt to take the snapshot may be required.

XenServer supports quiesced snapshots on:

  • Windows Server 2016

  • Windows Server 2012 R2

  • Windows Server 2012

  • Windows Server 2008 R2

  • Windows Server 2008 (32/64-bit)

Windows 8.1, Windows 8, Windows 7, Windows 2000, Windows XP, Windows 2003, and Windows Vista are not supported. For more information about quiesced snapshots, see Advanced Notes for Quiesced Snapshots.

Snapshots with memory

In addition to saving the VMs memory (storage) and metadata, snapshots with memory also save the VMs state (RAM). This feature can be useful when you upgrade or patch software, but you also want the option to revert to the pre-change VM state (RAM). Reverting to a snapshot with memory, does not require a reboot of the VM.

You can take a snapshot with memory of a running or suspended VM via the management API, the xe CLI, or by using XenCenter.

Create a VM snapshot

Before taking a snapshot, see the following information about any special operating system-specific configuration and considerations:

First, ensure that the VM is running or suspended so that the memory status can be captured. The simplest way to select the VM on which the operation is to be performed is by supplying the argument vm=name or vm=vm uuid.

Run the vm-snapshot and vm-snapshot-with-quiesce commands to take a snapshot of a VM.

xe vm-snapshot vm=vm uuid new-name-label=vm_snapshot_name
xe vm-snapshot-with-quiesce vm=vm uuid new-name-label=vm_snapshot_name

Create a snapshot with memory

Run the vm-checkpoint command, giving a descriptive name for the snapshot with memory, so that you can identify it later:

xe vm-checkpoint vm=vm uuid new-name-label=name of the checkpoint

When XenServer has completed creating the snapshot with memory, its uuid is displayed.

For example:

xe vm-checkpoint vm=2d1d9a08-e479-2f0a-69e7-24a0e062dd35 \
new-name-label=example_checkpoint_1
b3c0f369-59a1-dd16-ecd4-a1211df29886

A snapshot with memory requires at least 4 MB of disk space per disk, plus the size of the RAM, plus around 20% overhead. So a checkpoint with 256 MB RAM would require approximately 300 MB of storage.

Note:

During the checkpoint creation process, the VM is paused for a brief period, and cannot be used during this period.

To list all of the snapshots on your XenServer pool

Run the snapshot-list command:

xe snapshot-list

This command lists all of the snapshots in the XenServer pool.

To list the snapshots on a particular VM

Get the uuid of the particular VM by running the vm-list command.

xe vm-list

This command displays a list of all VMs and their UUIDs. For example:

xe vm-list
uuid ( RO): 116dd310-a0ef-a830-37c8-df41521ff72d
name-label ( RW): Windows Server 2012 (1)
power-state ( RO): halted

uuid ( RO): 96fde888-2a18-c042-491a-014e22b07839
name-label ( RW): Windows 2008 R2 (1)
power-state ( RO): running

uuid ( RO): dff45c56-426a-4450-a094-d3bba0a2ba3f
name-label ( RW): Control domain on host
power-state ( RO): running

VMs can also be specified by filtering the full list of VMs on the values of fields.

For example, specifying power-state=halted selects all VMs whose power-state field is equal to ‘halted’. Where multiple VMs are matching, the option --multiple must be specified to perform the operation. Obtain the full list of fields that can be matched by using the command xe vm-list params=all.

Locate the required VM and then enter the following:

xe snapshot-list snapshot-of=vm uuid

For example:

xe snapshot-list snapshot-of=2d1d9a08-e479-2f0a-69e7-24a0e062dd35

This command lists the snapshots currently on that VM:

uuid ( RO): d7eefb03-39bc-80f8-8d73-2ca1bab7dcff
name-label ( RW): Regular
name-description ( RW):
snapshot_of ( RO): 2d1d9a08-e479-2f0a-69e7-24a0e062dd35
snapshot_time ( RO): 20090914T15:37:00Z

uuid ( RO): 1760561d-a5d1-5d5e-2be5-d0dd99a3b1ef
name-label ( RW): Snapshot with memory
name-description ( RW):
snapshot_of ( RO): 2d1d9a08-e479-2f0a-69e7-24a0e062dd35
snapshot_time ( RO): 20090914T15:39:45Z

Restore a VM to its previous state

Ensure that you have the uuid of the snapshot that you want to revert to, and then run the snapshot-revert command:

  1. Run the snapshot-list command to find the UUID of the snapshot or checkpoint that you want to revert to:

    xe snapshot-list
    
  2. Note the uuid of the snapshot, and then run the following command to revert:

    xe snapshot-revert snapshot-uuid=snapshot uuid
    

    For example:

    xe snapshot-revert snapshot-uuid=b3c0f369-59a1-dd16-ecd4-a1211df29886
    

    After reverting a VM to a checkpoint, the VM is suspended.

Notes:

  • If there’s insufficient disk space available to thickly provision the snapshot, you cannot restore to the snapshot until the current disk’s state has been freed. If this issue occurs, retry the operation.

  • It is possible to revert to any snapshot. Existing snapshots and checkpoints are not deleted during the revert operation.

Delete a snapshot

Ensure that you have the UUID of the checkpoint or snapshot that you want to remove, and then run the following command:

  1. Run the snapshot-list command to find the UUID of the snapshot or checkpoint that you want to revert to:

    xe snapshot-list
    
  2. Note the UUID of the snapshot, and then run the snapshot-uninstall command to remove it:

    xe snapshot-uninstall snapshot-uuid=snapshot-uuid
    
  3. This command alerts you to the VM and VDIs that are deleted. Type yes to confirm.

For example:

xe snapshot-uninstall snapshot-uuid=1760561d-a5d1-5d5e-2be5-d0dd99a3b1ef
The following items are about to be destroyed
VM : 1760561d-a5d1-5d5e-2be5-d0dd99a3b1ef (Snapshot with memory)
VDI: 11a4aa81-3c6b-4f7d-805a-b6ea02947582 (0)
VDI: 43c33fe7-a768-4612-bf8c-c385e2c657ed (1)
VDI: 4c33c84a-a874-42db-85b5-5e29174fa9b2 (Suspend image)
Type 'yes' to continue
yes
All objects destroyed

If you only want to remove the metadata of a checkpoint or snapshot, run the following command:

xe snapshot-destroy snapshot-uuid=snapshot-uuid

For example:

xe snapshot-destroy snapshot-uuid=d7eefb03-39bc-80f8-8d73-2ca1bab7dcff

Snapshot templates

Create a template from a snapshot

You can create a VM template from a snapshot. However, its memory state is removed.

  1. Use the command snapshot-copy and specify a new-name-label for the template:

    xe snapshot-copy new-name-label=vm-template-name \
      snapshot-uuid=uuid of the snapshot
    

    For example:

    xe snapshot-copy new-name-label=example_template_1
      snapshot-uuid=b3c0f369-59a1-dd16-ecd4-a1211df29886
    

    Note:

    This command creates a template object in the SAME pool. This template exists in the XenServer database for the current pool only.

  2. To verify that the template has been created, run the command template-list:

    xe template-list
    

    This command lists all of the templates on the XenServer host.

Export a snapshot to a template

When you export a VM snapshot, a complete copy of the VM (including disk images) is stored as a single file on your local machine. This file has a .xva file name extension.

  1. Use the command snapshot-export-to-template to create a template file:

    xe snapshot-export-to template snapshot-uuid=snapshot-uuid \
      filename=template-  filename
    

    For example:

    xe snapshot-export-to-template snapshot-uuid=b3c0f369-59a1-dd16-ecd4-a1211df29886 \
      filename=example_template_export
    

The VM export/import feature can be used in various different ways:

  • As a convenient backup facility for your VMs. An exported VM file can be used to recover an entire VM in a disaster scenario.

  • As a way of quickly copying a VM, for example, a special-purpose server configuration that you use many times. You simply configure the VM the way you want it, export it, and then import it to create copies of your original VM.

  • As a simple method for moving a VM to another server.

For more information about the use of templates, see Create VMs and also the Managing VMs section in the XenCenter Help.

Advanced notes for quiesced snapshots

Note:

Do not forget to install the Xen VSS provider in the Windows guest to support VSS. This installation is done using the install- XenProvider.cmd script provided with the XenServer Tools. For more information, see Windows VMs.

In general, a VM can only access VDI snapshots (not VDI clones) of itself using the VSS interface. A XenServer administrator can add an attribute of snapmanager=true to the VM other-config allows that VM to import snapshots of VDIs from other VMs.

Warning:

This configuration opens a security vulnerability. Use it with care. With it, an administrator can attach VSS snapshots using an in-guest transportable snapshot ID as generated by the VSS layer to another VM for the purposes of backup.

VSS quiesce timeout: the Microsoft VSS quiesce period is set to a non-configurable value of 10 seconds. It is probable that a snapshot cannot complete in time. For example, if the XAPI daemon has queued extra blocking tasks such as an SR scan, the VSS snapshot may time out and fail. If this timeout happens, retry the operation.

Note:

The more VBDs attached to a VM, the more likely it is that this timeout may be reached. Citrix recommends attaching no more that 2 VBDs to a VM to avoid reaching the timeout. However, there is a workaround to this problem. The probability of taking a successful VSS based snapshot of a VM with more than 2 VBDs can be increased when all VDIs for the VM are on different SRs.

VSS snapshot all the disks attached to a VM: to store all data available at the time of a VSS snapshot. The XAPI manager takes a snapshot of all disks and the VM metadata associated with a VM that you can take a snapshot of by using the XenServer storage manager API. If the VSS layer requests a snapshot of only a subset of the disks, a full VM snapshot is not taken.

vm-snapshot-with-quiesce: Produces bootable snapshot VM images: The XenServer VSS hardware provider makes snapshot volumes writable, including the snapshot of the boot volume.

VSS snap of volumes hosted on dynamic disks in the Windows Guest: The vm-snapshot-with-quiesce CLI and the XenServer VSS hardware provider do not support snapshots of volumes hosted on dynamic disks on the Windows VM.

Note:

Do not forget to install the Xen VSS provider in the Windows guest to support VSS. This installation is done using the install-XenProvider.cmd script provided with the XenServer Tools. For more information, see Windows VMs.

Scheduled snapshots

The Scheduled Snapshots feature provides a simple backup and restore utility for your critical service VMs. Regular scheduled snapshots are taken automatically and can be used to restore individual VMs. Scheduled Snapshots work by having pool-wide snapshot schedules for selected VMs in the pool. When a snapshot schedule is enabled, Snapshots of the specified VM are taken at the scheduled time each hour, day, or week. Several Scheduled Snapshots may be enabled in a pool, covering different VMs and with different schedules. A VM can be assigned to only one snapshot schedule at a time.

XenCenter provides a range of tools to help you use this feature:

  • To define a Scheduled Snapshot, use the New snapshot schedule wizard.

  • To enable, disable, edit, and delete Scheduled Snapshots for a pool, use the VM Snapshot Schedules dialog box.

  • To edit a snapshot schedule, open its Properties dialog box from the VM Snapshot Schedules dialog box.

  • To revert a VM to a scheduled snapshot, select the snapshot on the Snapshots tab and revert the VM to it.

For more information about Scheduled Snapshots, see XenCenter Help.