Citrix Hypervisor

VM snapshots

Citrix Hypervisor 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 Citrix Hypervisor, 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.

The following types of VM snapshots are supported: regular and snapshot with memory.

Regular snapshots

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

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 by using 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-snapshotcommand to take a snapshot of a VM.

xe vm-snapshot vm=vm uuid new-name-label=vm_snapshot_name
<!--NeedCopy-->

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
<!--NeedCopy-->

When Citrix Hypervisor 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
<!--NeedCopy-->

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 Citrix Hypervisor pool

Run the snapshot-list command:

xe snapshot-list
<!--NeedCopy-->

This command lists all of the snapshots in the Citrix Hypervisor 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
<!--NeedCopy-->

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 2016 (1)
power-state ( RO): halted

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

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
<!--NeedCopy-->

For example:

xe snapshot-list snapshot-of=2d1d9a08-e479-2f0a-69e7-24a0e062dd35
<!--NeedCopy-->

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
<!--NeedCopy-->

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
    <!--NeedCopy-->
    
  2. Note the UUID of the snapshot, and then run the following command to revert:

    xe snapshot-revert snapshot-uuid=snapshot uuid
    <!--NeedCopy-->
    

    For example:

    xe snapshot-revert snapshot-uuid=b3c0f369-59a1-dd16-ecd4-a1211df29886
    <!--NeedCopy-->
    

    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
    <!--NeedCopy-->
    
  2. Note the UUID of the snapshot, and then run the snapshot-uninstall command to remove it:

    xe snapshot-uninstall snapshot-uuid=snapshot-uuid
    <!--NeedCopy-->
    
  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
<!--NeedCopy-->

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

xe snapshot-destroy snapshot-uuid=snapshot-uuid
<!--NeedCopy-->

For example:

xe snapshot-destroy snapshot-uuid=d7eefb03-39bc-80f8-8d73-2ca1bab7dcff
<!--NeedCopy-->

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
    <!--NeedCopy-->
    

    For example:

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

    Note:

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

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

    xe template-list
    <!--NeedCopy-->
    

    This command lists all of the templates on the Citrix Hypervisor server.

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
    <!--NeedCopy-->
    

    For example:

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

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 article in the XenCenter documentation.

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, see Scheduled Snapshots in the XenCenter documentation.

VM snapshots