how to use external snapshots with memory state

Peter Krempa pkrempa at redhat.com
Sun Jan 3 14:29:55 UTC 2021


On Fri, Jan 01, 2021 at 19:05:55 +0100, Riccardo Ravaioli wrote:
> Hi all,

Hi,

> 
> Best wishes for 2021! :)
> 
> So I've been reading and playing around with live snapshots and still
> haven't figured out how to use an external memory snapshot. My goal is to
> take a disk+memory snapshot of a running VM and, if possible, save it in
> external files.
> 
> As far as I understand, I can run:
> $ virsh snapshot-create $VM
> ... and that'll take an *internal* live snapshot of a given VM, consisting
> of its disks and memory state, which will be stored in the qcow2 disk(s) of
> the VM. In particular, the memory state will be stored in the first disk of
> the VM. I can then use the full range of snapshot commands available:
> revert, list, current, delete.
> 
> Now, an external snapshot can be taken with:
> $ virsh snapshot-create-as --domain $VM  mysnapshot --diskspec
> vda,file=/home/riccardo/disk_mysnapshot.qcow2,snapshot=external --memspec
> file=/home/riccardo/mem_mysnapshot.qcow2,snapshot=external
> ... with as many "--diskspec" as there are disks in the VM.
> 
> I've read the virsh manual and the libvirt API documentation, but it's not
> clear to me what exactly I can do then with an external snapshot, in
> particular with the file containing the memory state. In articles from 7-8
> years ago people state that external memory snapshots cannot be reverted...

Unfortunately that's still true. The external snapshot code provides
enough functionality that you are able to use them, but reverting and
deleting needs to be done manually. There are a few manuals floating
online but it always depends on what you want to achieve.

The unfortunate situation of the implementation not being finished (I've
certainly stated it here already, since this question happens from time
to time (which also means you should look through the archives and
you'll find some pointers how to do certain specific steps)) comes from
the fact that it provides enough functionality for higher level
management projects to control snapshots (oVirt, openstack) and too much
higher priority work.

> is it still the case today? If so, what's a typical usage for such files?
> If not with libvirt, is it possible to revert to an external memory + disk

The memory image created by libvirt this way is actually in the same
image format as 'virsh save' and 'virsh restore' uses. This actually
does allow you to restore such a snapshot, although manual steps are
necessary. The most naive scenario, where you want to return to the
past state and you don't require returning back (alternate future is not
created) can be reverted simply by simply using 'virsh restore $IMG' and
then fixing the persistent definition of the VM to use the same disk
images as the memory image recorded.

Note that the overlay images which were created as part of the snapshot
are invalid after that point and must no longer be used.

Similarly, for non-active VMs or vms without memory snapshot you can
alter the image locations to use the old images and that effectively
reverts the snapshot.

Other operations are possible too, but please look through the archives
first.

> state in other ways, for instance through qemu commands?
> 
> Thanks!
> 
> Riccardo




More information about the libvirt-users mailing list