TT Lab
Get started
Learn Learning paths Courses

Virtualisation with QEMU/KVM

Two Ways to Snapshot

Continue in TT Lab

Goal

Create both internal snapshots and external snapshots of qcow2, and confirm the difference between the two methods in the actual file structure.

Why it matters

Internal snapshots are convenient because they are managed as a single file, but they are hard to back up — because the original keeps changing. An external snapshot creates a new overlay that uses the current image as its backing and freezes the original at that point. That is why a backup tool can copy the original safely, and this is the standard of practical backup workflows. Rolling back is simple too, ending with discarding the overlay. In exchange, the number of files grows and you need to manage the chain.

Note: you must not touch an image with qemu-img while the VM is running. This lab proceeds only in a stopped state.

Steps

  1. Create the /root/snap directory and create /root/snap/disk.qcow2 as a 1G qcow2.
  2. Create an internal snapshot named before-upgrade.
  3. Save the snapshot list to /root/snap/list1.txt. before-upgrade must be visible.
  4. Create two more, after-patch and rollback-point, and save the list to /root/snap/list3.txt. There must be exactly 3 snapshots.
  5. Apply (roll back to) the before-upgrade snapshot, and write the exit code of that command to /root/snap/applied.txt in the form rc=0.
  6. Delete the after-patch snapshot, and save the remaining list to /root/snap/list2.txt. There must be exactly 2 snapshots.
  7. Create an external snapshot. Create /root/snap/disk.ext1.qcow2 with disk.qcow2 as its backing, and save the backing chain output to /root/snap/chain.txt.
  8. Create /root/snap/compare.txt with the following 4 lines. INTERNAL_COUNT=<6번 이후 남은 내부 스냅샷 개수> / EXTERNAL_FILES=2 / BACKUP_FRIENDLY=external / ROLLBACK_INTERNAL=-a (the placeholder is the number of internal snapshots remaining after step 6)

Notes

Prepare the lab image

Create the /root/snap directory and create /root/snap/disk.qcow2 as a 1G qcow2.

Use a new image separate from the previous lab. A small size is fine.

Create an internal snapshot

Create an internal snapshot named before-upgrade.

The -c of qemu-img snapshot is create. You give the name as an argument.

Snapshot list

Save the snapshot list to /root/snap/list1.txt. before-upgrade must be visible.

-l shows the ID, TAG, size, and time as a table. There are header lines, so be careful when counting.

Create several points in time

Create two more, after-patch and rollback-point, and save the list to /root/snap/list3.txt. There must be exactly 3 snapshots.

Just repeat the same command, changing only the name. Three must be visible in the list.

Roll back to a snapshot

Apply (roll back to) the before-upgrade snapshot, and write the exit code of that command to /root/snap/applied.txt in the form rc=0.

-a rolls the image contents back to the specified snapshot's point in time. The list itself remains.

Delete a snapshot

Delete the after-patch snapshot, and save the remaining list to /root/snap/list2.txt. There must be exactly 2 snapshots.

If you delete one with -d, it disappears from the list. Check the remaining count.

Create an external snapshot

Create an external snapshot. Create /root/snap/disk.ext1.qcow2 with disk.qcow2 as its backing, and save the backing chain output to /root/snap/chain.txt.

Creating a new overlay that uses the current image as its backing is itself an external snapshot.

Comparison table of the two methods

Create /root/snap/compare.txt with the following 4 lines. INTERNAL_COUNT=<6번 이후 남은 내부 스냅샷 개수> / EXTERNAL_FILES=2 / BACKUP_FRIENDLY=external / ROLLBACK_INTERNAL=-a (the placeholder is the number of internal snapshots remaining after step 6)

The values must be what you actually confirmed in the earlier steps. Judge backup friendliness by whether the original is fixed.