KVM - The Linux Kernel-Based Virtual Machine
News, Blogs and Resources on the Linux (KVM) Kernel-Based Virtual Machine

First Look: Virtual machine online disk snapshots coming to Fedora 18

In this post I will preview the new live disk snapshotting feature coming to Fedora 18.  This is a very attractive feature that will give you the ability to take online snapshots of your virtual disks while running with no downtime. This is as opposed to the old qemu snapshotting feature which incurred some downtime even if it was for a short period.  This is ideal for backups allowing you to essentially perform online backups of your virtual disks.  Support for this new feature has already been added to libvirt but not libvirt dependent GUI management tools like virt-manager as yet so it is currently limited to command line. 


Disk Snapshot


Online backups using live snapshots

I will be demonstrating using a fedora 17 install as the basic features are already available on Fedora 17 and virsh and libvirt is currently unusable in Fedora 18 due to bugs.  To begin, launch a virtual machine using virt-manager or virsh then open a virsh session using the virsh command and list your domains.  In the example below you can see my domain called winxp running.

virsh # list --all

 Id    Name                           State
 1     winxp                          running


Next create a live snapshot using the snapshot-create-as command.  In this example I called the snapshot snapshot1.  Be sure to use the --disk-only and --atomic keywords with this command.  

virsh # snapshot-create-as winxp snapshot1 "First snapshot" --disk-only --atomic
Domain snapshot snapshot1 created

This will instantly create an external snapshot as an external file on your filesystem with the name of your snapshot as the suffix.  In my example you can see the original disk image file and the snapshot image file.

[root@localhost images]# ls -ltr
total 1481552
-rw-------. 1 qemu qemu 1439825920 Aug 13 00:44 WindowsXPInstall.img
-rw-------. 1 qemu qemu   77398016 Aug 13 00:47 WindowsXPInstall.snapshot1

At this point if you look at your virt-manager disk properties you will see it updated now showing your snapshot file rather than the previous base image that you booted.


online disk snapshot


Note also the small size of the snapshot as it is a newly created file where new disk writes will reside.  Naturally this file will be much smaller than your original base image.  At this point your base image can be safely backed up while your virtual machine is running.  Your backup will not contain anything after the time of snapshot creation.

If you issue the snapshot-list command in virsh you will see your snapshot listed.

virsh # snapshot-list winxp
 Name                 Creation Time             State
 snapshot1            2012-08-13 00:44:48 -0400 disk-snapshot

The qemu-img info command will also show the link between your snapshot file and your base image.  Your snapshots will always be in the qcow2 file format.

[root@localhost images]# qemu-img info WindowsXPInstall.snapshot1
image: WindowsXPInstall.snapshot1
file format: qcow2
virtual size: 5.9G (6291456000 bytes)
disk size: 365M
cluster_size: 65536
backing file: /home/hsolomon/images/WindowsXPInstall.img (actual path: /home/hsolomon/images/WindowsXPInstall.img)

Once your backup is completed you can merge your snapshot file back into your base image file with the following virsh blockpull command.

virsh # blockpull --domain winxp --path /home/hsolomon/images/WindowsXPInstall.img --base /home/hsolomon/images/WindowsXPInstall.snapshot1

Unfortunately the blockpull command is not yet supported in Fedora 17's qemu but will be in Fedora 18.  If you try to run it on Fedora 17 at this time you will get the following error.

error: Requested operation is not valid: Command 'block_stream' is not found

There are some other planned features related to live snapshotting such as reverting to older snapshots in your snapshot tree and deleting external snapshot files from within virsh.  These features will be coming at some point in the future but the commands listed above are the main ones planned for Fedora 18.


Wrap Up

This was a preview of the planned live snapshotting feature in development and scheduled for release with Fedora 18.   Some of these features are already available in Fedora 17 as demonstrated but won't be fully available until the next release. Live disk snapshotting will be a huge benefit and time saver for backing up KVM virtual machines online and adds production level features to KVM for free.  Online backups could be scheduled and run automatically with such a feature.  Adding this feature to libvirt tools like virt-manager and RHEV will be sure to follow.

See Also


Lvm ?

Great news! Does it work with LVM based VM?


I believe that it should work although I have not tested this.

Hello,i am using qemu-kvm

Hello,i am using qemu-kvm with libvirt on centos6.3,i found that the
qemu-kvm does not support disk only snapshot,
when i use virsh snapshot-create-as --disk-only ,it will raise an
error :the qemu-kvm binary does not support blkdev_snapshot
but the qemu-kvm-rhev which come from RHEV works .

is there any one know why the qemu-kvm-el6 does not support disk only
snapshot feature?

Open files corrupt?

If one takes snapshots like this, there should also be a snapshot of the current run memory (RAM/virtual memory/swap) included, no?

Stable Virtual Machine

This does work for sure. The Fedora 18 Virtual Machine works well with snapshots. Looking forward for the stable release. Cheers, --Emil.

error in blockpull?

From my tests, there's an error in the blockpull command. --base and --path are inverted in the example.

Post new comment

The content of this field is kept private and will not be shown publicly.
Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.