[libvirt-users] snapshot of a raw file - how to revert ?

Kashyap Chamarthy kchamart at redhat.com
Thu Feb 15 11:10:05 UTC 2018


On Tue, Feb 13, 2018 at 01:38:34PM +0100, Lentes, Bernd wrote:
> Hi,

[...]


> I have several guests running with raw files, which is sufficent for
> me. Now i'd like to snapshot one guest because i make heavy
> configuration changes on it.  From what i read in the net is that
> libvirt supports snapshoting of raw files when the guest is shutdown
> and the file of the snapshot becomes a qcow2. Right ?  

The guest doesn't have to be shutdown.

First of all the term "snapshot" is a bit overloaded.  There are
different kinds of snapshots.  Refer slide-7 here[*].

In your case, since you want to take a snapshot of a raw disk image,
we'll be talk about "external snapshots".  So let's spell out what
exactly happens when you try to take live snapshot of a raw disk image.

If you have a disk image (to which live QEMU is writing):  

    A.raw (live QEMU)

When you create an "external snapshot" as below:

  $ virsh snapshot-create-as --domain vm1 disk-state1 \
      --diskspec vda,file=/export/images/B.qcow2 \
      --disk-only --atomic 

You will get the following:

    A.raw <-- B.qcow2 (live QEMU)

What it means is the original A.raw is turned into a read-only backing
file.  A new QCOW2 "overlay" (B.qcow2) is created, and all the new
writes from now on will happen in B.qcow2.

In the above scenario, `virsh snapshot-revert` will not work (as of
now).  If you now want to rever to A.raw, you have to:

(1) Shutdown the guest:

  $ virsh shutdown vm1

(2) Edit the guest XML so that it now points to A.raw:

  $ virsh edit vm1

  And update the 'source file' attribute:
  ...
  <disk type='file' device='disk'>
   <driver name='qemu' type='raw'/>
   <source file='/my/A.raw'/>
  ...

(3) Start the guest again:

  $ virsh start vm1

    * * *

If you want to take backups, there's a cleaner way:

    https://wiki.libvirt.org/page/Live-disk-backup-with-active-blockcommit

The above is possible with QEMU 2.1 (and above), libvirt-1.2.9 (and
above).  So, in your environment, you have to upgrade.

> I try to avoid converting my raw file to a qcow2 file. I can shutdown
> the guest for a certain time, that's no problem. I don't need a live
> snapshot.  But how can i revert to my previous state if my
> configuration changes go wrong ?  Can i do this with snapshot-revert
> or do i have to edit the xml file and point the hd again to the origin
> raw file ?  What i found in the net wasn't complete clear.

I answered your questions above to keep them in one place.  (Yes, you're
right — you have to edit the XML file and point to the original disk.)

The command `virsh snapshot-revert` works only with "internal snapshots"
— where your original and the delta, all of them reside in the single
QCOW2 file.


PS: I also fixed the quoting in your email, it was a bit off.

[*] https://kashyapc.fedorapeople.org/virt/lc-2012/lceu-2012-virt-snapshots-kashyap-chamarthy.pdf

-- 
/kashyap




More information about the libvirt-users mailing list