martedì 20 agosto 2013

About KVM QCOW2 Live backup

Today I've had to work with a cluster made of QEMU-KVM and using QCOW2 as storage format for VM disk.
It's a cool platform for hosting VM; it's Linux based, so if anything doesn't work I (and those who knows) can go deeply inside the system and find the reason.
But it's not as easy as you can think... I came from VMWare world, where everything is deeply tested (I hope) and easy to do.

My problem now was to find a way to make "hot" backups of VM running with QCOW2 disks. The best practice for store disk images is to use LVM and take snapshots by using the underlying volume manager, so mount the snapshot in read-only and extract files to backup.

I am against this procedure for 3 things:

  1.  It's "dirty" in sense that it freezes the I/O at device level
  2.  It's architecture dependent: the host OS needs to be able to mount the snapshot to extract files (= understand the filesystem)
  3.  It's so much different from VMWare approach to backups

Yes, LVM volumes are cool, I must say that, and they guarantee high performances... but they don't feet my needs.

So how can I do the backup ?

By googling I've found an interesting discussion here. One of the members is Eric Blake from RedHat, so a trusted author, almost for me.

So, by reading this, I've made a small shell script (called bkvm, which you can download) that makes backup using the blockcopy feature of libvirt/qemu. It doesn't stop VM, but guarantees (if blockcopy does it work) data integrity by saving both volumes and VM state.
The maximum downtime is the one needed to save VM memory and restore it (about 30 seconds for a 4 GB memory VM).

I've tested it on libvirt 1.0.6 and qemu-1.5; don't blame me if it destroys you system :-)

I'm obviously in no way responsible for damages which this script could cause to your system.. If you wanna try it, remember that the default directory it uses for backup is /mnt/local_vmbackup but you can easily change it via shell arguments.

If anyone is using it, let me know your impression.

This is the first post of my techie-blog. Here you'll find many interesting (for me) things I'm doing.