KVM Snapshots

Questions about applications and software
Forum rules
Before you post please read how to get help
dobriain
Level 1
Level 1
Posts: 42
Joined: Sat Dec 06, 2014 1:26 pm

KVM Snapshots

Postby dobriain » Fri Jan 08, 2016 1:45 am

I am working with KVM and could create a domain (VM) snapshot with the virsh command:

Code: Select all

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.

Code: Select all

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


Code: Select all

$ 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).

Code: Select all

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?

dobriain
Level 1
Level 1
Posts: 42
Joined: Sat Dec 06, 2014 1:26 pm

Re: KVM Snapshots

Postby dobriain » Wed Jan 13, 2016 10:56 am

Guess I will have to answer my own question.

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.

Code: Select all

  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.

Code: Select all

  virsh # edit vm01 


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

Code: Select all

    ....
    ....
     
      <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:

Code: Select all

    ....
    ....
      <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.

Code: Select all

  Domain vm01 XML configuration edited.


Now start the domain.

Code: Select all

  virsh # start vm01
  Domain vm01 started


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

Code: Select all

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


Return to “Software & Applications”

Who is online

Users browsing this forum: No registered users and 11 guests