lima icon indicating copy to clipboard operation
lima copied to clipboard

Does lima support checkpoint backup and restore like normal virtual machine?

Open jandubois opened this issue 3 years ago • 6 comments

Discussed in https://github.com/lima-vm/lima/discussions/1050

Originally posted by f91og September 13, 2022 Just want to quick restore to a certain status after tried several things that caused develop environment broken

jandubois avatar Sep 13 '22 16:09 jandubois

It should be possible to create something with the qemu savevm and loadvm commands:

Does qemu emulator have checkpoint function? - Stack Overflow]

jandubois avatar Sep 13 '22 16:09 jandubois

Apparently these are missing from (older versions of ?) QMP, so might need be issued differently (monitor?).

https://github.com/digitalocean/go-qemu

https://lore.kernel.org/all/[email protected]/

savevm, loadvm and delvm are some of the few commands that have never been converted to use QMP. The primary reason for this lack of conversion is that they block execution of the thread for as long as they run.

It also hints at the workaround: (HumanMonitorCommand)

Despite this downside, however, libvirt and applications using libvirt has used these commands for as long as QMP has existed, via the "human-monitor-command" passthrough command. IOW, while it is clearly desirable to be able to fix the blocking problem, this is not an immediate obstacle to real world usage.

afbjorklund avatar Sep 13 '22 16:09 afbjorklund

It seems to work OK, but it's not straight-forward how to list the existing snapshots... (i.e. need to remember the tag)

$ ~/qemu/scripts/qmp/qmp-shell -H ~/.lima/default/qmp.sock
Welcome to the HMP shell!
Connected to QEMU 4.2.1

(QEMU) savevm my-tag
(QEMU) loadvm my-tag
(QEMU) 

Once the instance is offline, it is possible to list the existing snapshots: qemu-img snapshot -l ~/.lima/default/diffdisk

qemu-img: Could not open '/home/anders/.lima/default/diffdisk': Failed to get shared "write" lock
Is another process using the image [/home/anders/.lima/default/diffdisk]?
$ qemu-img snapshot -l ~/.lima/default/diffdisk 
Snapshot list:
ID        TAG                     VM SIZE                DATE       VM CLOCK
1         my-tag                 1.11 GiB 2022-09-14 19:03:55   00:01:08.816

afbjorklund avatar Sep 14 '22 17:09 afbjorklund

Beyond backup (savevm) and restore (loadvm), might want to add a third command for removing a snapshot (delvm) ?

As a workaround, it is also possible to do it with qemu-img snapshot -d my-tag ~/.lima/default/diffdisk outside of lima

afbjorklund avatar Sep 14 '22 17:09 afbjorklund

Newer versions of qemu-img default to read-only images, which means that the command will work on running instances...

For older versions, it is possible to use the --force-share flag with the snapshot -l command (it should still be safe)

afbjorklund avatar Sep 15 '22 09:09 afbjorklund

Now a single command, with sub-commands:

Usage:
  limactl snapshot [command]

Available Commands:
  apply       Apply (load) a snapshot
  create      Create (save) a snapshot
  delete      Delete (del) a snapshot
  list        List existing snapshots

afbjorklund avatar Oct 02 '22 15:10 afbjorklund