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