KVM Snapshots

dobriain's picture

Forums: 

I would be much obliged if someone could help me. I have been pulling my hair out with KVM and trying to do snapshots. Google has not been my friend in this instance and after spending a day doing blockpull, block copy etc.. I am not getting anywhere fast.

I can create a domain (VM) snapshot with the virsh command:

    virsh # snapshot-create-as vm01 snapshot01 “Snapshot of vm01” —disk-only —atomic
    Domain snapshot snapshot01 created

This created a QEMU Copy or Write (QCOW) snapshot image.

    virsh # snapshot-list vm01
    Name          Creation Time             State
    -----------------------------------------------------
    snapshot01    2016-01-06 20:11:14 +0000 disk-snapshot

    $ sudo file /virt/kvm/images/vm01.snapshot01
    vm01.snapshot01: QEMU QCOW Image (v3), has backing file (path /virt/kvm/images/vm01.img), 12884901888 bytes

While the command to revert exists in libvirt it is not yet working with KVM (presumably it is there for Xen).

    virsh # snapshot-revert —domain vm01 snapshot01
    error: unsupported configuration: revert to external snapshot not supported yet

So to my questions;

1) is there a way of recovering back to the snapshot I created ?
2) when is it expected that the existing virsh command for reverting will work with KVM?
3) Is there an issue around RAW images as the original image ?

KVM Snapshots

dobriain's picture

Well I guess I will need to answer the question myself.

1) is there a way of recovering back to the snapshot I created ?

Yes there is, see below.

2) when is it expected that the existing virsh command for reverting will work with KVM ?

Apparently there are issues that will not be resolved quickly.

3) Is there an issue around RAW images as the original image ?

None, the original image can be RAW but snapshots will be qcow2 format.

Revert to a previous snapshot

Unfortunately the virsh command snapshot-revert vm01 snap01-vm01.img is not yet working with KVM, however it is quite simple to make the revert.
Shutdown the domain, a simple shutdown of the guest OS is fine. And confirm it is in-fact not running.

  virsh # list --all
   Id    Name            State
  ------------------------------------
   2     vm02 running
   3     vm03 running
   -     vm01    shut off

Edit the domain XML file to change the name of the image back to the original.

  virsh # edit vm01

Change the source file to the original image and change the type to raw to match the original image.

    ....
    ....
     
      <disk type='file' device='disk'>
        <driver name='qemu' type='qcow2'/>
        <source file='/virt/kvm/images/snap01-vm01.img'/>
        <target dev='vda' bus='virtio'/>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
      </disk>
    ....
    .... 

to:
    ....
    ....
      <disk type='file' device='disk'>
        <driver name='qemu' type='raw'/>
        <source file='/virt/kvm/images/vm01.img'/>
        <target dev='vda' bus='virtio'/>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
      </disk>
    ....
    ....

The change is confirmed back to the console.

  Domain vm01 XML configuration edited.

Now start the domain.

  virsh # start vm01
  Domain vm01 started

Check the running domain block device. It has reverted to the original image.

  virsh # domblklist vm01
  Target     Source
  --------------------------------------
  vda        /virt/kvm/images/vm01.img
  hdc        -