Backing up qcow2 kvm guests

backupkvm-virtualizationvirtual-machinesvirtualization

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:

  1. suspend virt_machine # pause virtual machine
  2. rsync –sparse /home/vm/image.qcow2 /tmp/image.dec_14_2010.qcow2 # copy the image on the same drive
  3. resume virt_machine
  4. 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.

Best Answer

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