Snapshots
A snapshot captures the state of a VM at a point in time: its disks, and optionally its RAM. Snapshots are the base of quick rollbacks ("let me try this upgradeβ¦") and of delta backups.
Snapshots are not backups: they live on the same SR as the VM. If the storage is lost, snapshots are lost with it. For real backups (full, delta, replicated, off-siteβ¦), use Xen Orchestra backup.
π How they workβ
XCP-ng disks are copy-on-write: taking a snapshot freezes the current disk state as a read-only parent, and the VM continues writing into a new child disk. This makes snapshot creation almost instant, but it has consequences:
- Each snapshot extends the disk chain; a long chain slightly degrades I/O performance.
- Snapshots consume space on the SR (on thick-provisioned SRs like LVM/iSCSI/HBA, a snapshot can reserve up to the full disk size).
- Deleting a snapshot doesn't free space immediately: the coalesce process has to merge the chain in the background first.
πΈ Take a snapshotβ
Two flavors:
- Disk-only snapshot: captures the disks. Works on a running or halted VM.
- Snapshot with RAM (also called checkpoint): additionally saves the VM's memory. Reverting resumes the VM exactly where it was, running. Requires working guest tools and takes longer.
From Xen Orchestra: VM β Snapshots tab β new snapshot (with an option to also snapshot the RAM). With xe:
# xe vm-snapshot vm="my-vm" new-name-label="before-upgrade" # xe vm-checkpoint vm="my-vm" new-name-label="before-upgrade-with-ram"
In Xen Orchestra you can exclude specific disks from snapshots (and backups) by naming convention: putting [NOSNAP] (snapshots) or [NOBAK] (backups and their snapshots) in the disk's name. Very useful for large scratch/data disks. On XCP-ng 8.3, disk exclusion is supported natively by the snapshot API, which XO uses.
βͺ Revert to a snapshotβ
Reverting replaces the VM's current state with the snapshot's state. Everything written since the snapshot is lost.
From Xen Orchestra: Snapshots tab β revert. With xe:
# xe snapshot-list snapshot-of=<vm-uuid> # xe snapshot-revert snapshot-uuid=<snapshot-uuid>
After reverting, the VM is halted (or suspended for a RAM snapshot; resume it to continue exactly where it was). The snapshot itself survives the revert, so you can revert again later.
ποΈ Delete a snapshotβ
From Xen Orchestra: Snapshots tab β delete. With xe:
# xe snapshot-uninstall snapshot-uuid=<snapshot-uuid>
Space is reclaimed asynchronously by the coalesce process: expect a delay (and storage I/O activity) before the SR usage drops. If space never comes back, check that coalesce isn't stuck.
π Scheduled (rolling) snapshotsβ
Use Xen Orchestra's Rolling Snapshot backup jobs: take a snapshot of selected VMs on a schedule and keep the N most recent ones. This gives you automatic short-term rollback points at near-zero cost. See the XO backup documentation for details, and remember the warning above: schedule real backups too.
π§° Other things you can do with a snapshotβ
- Create a template from it (golden image without stopping the source VM).
- Create a full VM from it:
xe snapshot-copy snapshot-uuid=<uuid> new-name-label="restored-vm"(or from Xen Orchestra, "create VM from snapshot"). - Export it as an XVA file:
xe snapshot-export-to-template snapshot-uuid=<uuid> filename=snap.xva(see import and export).