Backing up qcow2 kvm guests
I can't find any good info on backing up qcow2 kvm guests. I'm not really interested in the guests running state, only the file system. This question suggests using savevm
but that creates a snapshot in place. I'd like to backup the filesystem remotely.
Is there a better way than:
- suspend virt_machine # pause virtual machine
- rsync --sparse /home/vm/image.qcow2 /tmp/image.dec_14_2010.qcow2 # copy the image on the same drive
- resume virt_machine
- rsync --sparse /tmp/image.dec_14_2010.qcow2 ssh://backup@backupmachine:/vmbackups
There are a couple of downsides to this. First, copying a huge image file takes a (relatively) long time. Secondly, I must always make sure that I have enough space to backup my machines. This is not ideal. Are there any other better ways of managing KVM backups?
Thanks.
Solution 1:
I would suggest qemu-nbd's snapshot feature:
qemu-nbd --snapshot --connect=/dev/nbd0 image.qcow2
then mount /dev/nbd0p1 (partition 1), rsync, unmount and finally disconnnect:
qemu-nbd --disconnect /dev/nbd0
Solution 2:
Dirty image with this (your pause can probably help, but still might not be fully consistent):
Do a snapshot on LVM file system holding the qcow2 sparse file (again assuming you have room for the LVM snapshot)
Mount the LVM snapshot.
Mount the remote using sshfs.
Copy to the sshfs mountpoint using sparse copy (cp --sparse=always src dest)
Less time to copy, but still will take up to the full time if the image is mostly full.
Backups of data from within the VM are probably a better idea (less space / time). Treat the individual vm's as regular hosts to be backed up / restored - i.e. just get what you need and keep a set of stub vm's without the data to get back up and running fast.
Solution 3:
Personally, I've had a VERY difficult time with this issue and have found that, even when quiesced, the guest backups were often flaky. Remember -- if you are not regularly trying to restore these backups, you really have no idea if they work.
After a lot of experimentation, I punted on image backup entirely and went with a traditional network backup solution that one might use for bare metal servers. In my case we went with BackupPC, which is old, but super reliable. On each server, I configured the backup solution for the particular application(s) in use. For example sqldump for MySQL, plugin for Joomla, etc.
It's a PIA, but it is far faster, and very reliable.
Solution 4:
No matter where you do the snapshot - LVM or qcow2, the VM still needs to be quiesced before you take it. Otherwise you get lost data and corrupted images.