2.12. Managing Snapshots

In Virtuozzo Hybrid Server, you can save the current state of a virtual machine or container by creating a snapshot. You can then continue working in your virtual machine or container and return to the saved state any time you wish. Snapshots may be useful in the following cases:

  • Configuring applications with a lot of settings. You may wish to check how settings work before applying them to the application. So, before you start experimenting, you create a snapshot.

  • Participating in large-scale development projects. You may wish to mark development milestones by creating a snapshot for each. If anything goes wrong, you can easily revert to the previous milestone and resume the development.

In Virtuozzo Hybrid Server, you can create, list, revert to, and delete snapshots. These operations are described in the following subsections.

2.12.1. Creating Snapshots

To create a snapshot of a virtual machine or container, use the prlctl snapshot command.

2.12.1.1. Creating Virtual Machine Snapshots

To create a snapshot of the virtual machine MyVM, do the following:

# prlctl snapshot MyVM
...
The snapshot with ID {12w32198-3e30-936e-a0bbc104bd20} has been successfully created.

A newly created snapshot is saved to the /vz/vmprivate/<UUID>/snapshots/<snapshot_ID>/config.pvs file, where <UUID> is the corresponding virtual machine ID and <snapshot_ID> is a unique snapshot ID. In the above example, the snapshot with the ID {12w32198-3e30-936e-a0bbc104bd20} is saved to the file /vz/vmprivate/d35d28e5-11f7-4b3f-9065-8fef6178bc5b/snapshots/{12w32198-3e30-936e-a0bbc104bd20}/config.pvs.

# ls /vz/vmprivate/d35d28e5-11f7-4b3f-9065-8fef6178bc5b/snapshots/
{12w32198-3e30-936e-a0bbc104bd20}/config.pvs

Snapshot IDs are needed to switch to and delete snapshots.

When creating a snapshot, you can also set its name and description:

# prlctl snapshot MyVM -n Clean_System -d "This snapshot was created right after \
 installing Windows XP."
...
The snapshot with ID {0i8798uy-1eo0-786d-nn9ic106b9ik} has been successfully created.

You can view the set name and description in the /vz/vmprivate/d35d28e5-11f7-4b3f-9065-8fef6178bc5b/snapshots/{12w32198-3e30-936e-a0bbc104bd20}/snapshot.xml file.

2.12.1.2. Creating Container Snapshots

To create a snapshot of the container MyCT, do the following:

# prlctl snapshot MyCT
...
The snapshot with ID {08ddd014-7d57-4b19-9a82-15940f38e7f0} has been successfully \
created.

A newly created snapshot is saved to the /vz/private/<UUID>/dump/<snapshot_ID>.ve.conf file, where <UUID> is the container UUID and <snapshot_ID> is a snapshot ID. In the example above, the snapshot with the ID {08ddd014-7d57-4b19-9a82-15940f38e7f0} is saved to the file /vz/private/26bc47f6-353f-444b-bc35-b634a88dbbcc/dump/{08ddd014-7d57-4b19-9a82-15940f38e7f0}.ve.conf.

# ls /vz/private/26bc47f6-353f-444b-bc35-b634a88dbbcc/dump
{08ddd014-7d57-4b19-9a82-15940f38e7f0}.ve.conf

Snapshot IDs are needed to switch to and delete snapshots.

When creating a snapshot, you can also set its name and description:

# prlctl snapshot MyCT -n Clean_System -d "This snapshot was created right after \
installing Windows XP."
...
The snapshot with ID {e78bb2b8-7a99-4c8b-ab9a-491a47648c44} has been successfully \
created.

The set name and description are stored in the /vz/private/<UUID>/Snapshots.xml file.

2.12.1.3. Snapshot Branching

Snapshot branches can be useful for working with, testing or comparing similar configurations. A snapshot branch is created when you do the following:

  1. Create several snapshots.

  2. Revert to one of the snapshots.

  3. Make changes to the virtual machine or container.

  4. Create a snapshot.

In this case, the newly created snapshot will start a new branch based on the snapshot from Step 2.

2.12.1.4. Restrictions and Recommendations

  • If a virtual machine or snapshot name or description contains spaces, enclose it in quotation marks (e.g., “Windows XP”) in the prlctl command.

  • Before creating a snapshot, it is recommended that you finish any installations, downloads, and stop writing to external devices. You should also complete or cancel any transactions performed via the virtual machine in external databases.

  • You cannot create snapshots for containers with enabled NFS server feature.

2.12.2. Listing Snapshots

To list all snapshots of a particular virtual machine or container, use the prlctl snapshot-list command. For example, to check all current snapshots of the virtual machine MyVM, run this command:

# prlctl snapshot-list MyVM
PARENT_SNAPSHOT_ID                       SNAPSHOT_ID
                                         {989f3415-3e30-4494-936e-a0bbc104bd20}
{989f3415-3e30-4494-936e-a0bbc104bd20}  *{063615fa-f2a0-4c14-92d4-4c935df15840}

This command shows that the virtual machine MyVM has two snapshots. The snapshot with ID {063615fa-f2a0-4c14-92d4-4c935df15840} is based on the snapshot with ID {989f3415-3e30-4494-936e-a0bbc104bd20}, i.e. the former is a child of the latter. The asterisk marks the current snapshot.

To view the relationships between snapshots, use the -t option:

# prlctl snapshot-list MyVM -t
_{989f3415-3e30-4494-936e-a0bbc104bd20}_{063615fa-f2a0-4c14-92d4-4c935df15840}\
*{712305b0-3742-4ecc-9ef1-9f1e345d0ab8}

The command output shows you that currently two branches exist for the virtual machine MyVM. The snapshot with ID {989f3415-3e30-4494-936e-a0bbc104bd20} is the base for these branches.

To get detailed information on a particular snapshot, use the -i option with the snapshot ID:

# prlctl snapshot-list MyVM -i {063615fa-f2a0-4c14-92d4-4c935df15840}
ID: {063615fa-f2a0-4c14-92d4-4c935df15840}
Name: Clean_System
Date: 2012-07-22 22:39:06
Current: yes
State: poweroff
Description: <![CDATA[This snapshot was created right after installing Windows 7]]>

The prlctl snapshot-list command with the -i option displays the following information about snapshots:

Field

Description

ID

ID assigned to the snapshot.

Name

Name assigned to the snapshot.

Date

Date and time when the snapshot was created.

Current

Denotes that this is the current snapshot of the virtual machine.

State

State the virtual machine was in at the time you took the snapshot.

Description

The description set for the snapshot.

2.12.3. Reverting to Snapshots

To revert to a snapshot, use the prlctl snapshot-switch command. When you revert to a snapshot, the current state of the virtual machine or container is discarded, and all changes made to the system since the previous snapshot are lost. So, before reverting, you may want to save the current state by creating a new snapshot (see Creating Snapshots).

The prlctl snapshot-switch command requires the virtual machine or container name and the snapshot ID as arguments, for example:

# prlctl snapshot-switch MyVM --id {cedbc4eb-dee7-42e2-9674-89d1d7331a2d}

In this example, you revert to the snapshot {cedbc4eb-dee7-42e2-9674-89d1d7331a2d} for the virtual machine MyVM.

2.12.4. Deleting Snapshots

To delete unneeded snapshots of virtual machines or containers, use the prlctl snapshot-delete command. For example:

# prlctl snapshot-delete MyVM --id {903c12ea-f6e6-437a-a2f0-a1d02eed4f7e}

When you delete a parent snapshot, child snapshots are not deleted, and the information from the former is merged into the latter.