How to (properly) back up a live QEMU/KVM VM?

Posted by Roman on Server Fault See other posts from Server Fault or by Roman
Published on 2013-08-14T08:17:12Z Indexed on 2013/10/24 9:59 UTC
Read the original article Hit count: 223

Filed under:
|

I'm currently engineering a backup solution for KVM VM's as an additional measure to traditional backups.

Unfortunately, all currently (August 2013) existing solutions I came across so far either:

  • do not ensure a consistent backup of the VM (losing RAM state, creating a dirty image, or other things),
  • or require lengthy downtime (complete VM shutdown while backing up).

I'm aware of QEMU/libvirt's functionality of taking snapshots, however, it's not yet usable since:

  • image-internal snapshots present you with an ever-changing image file, resulting in a likely dirty backup (assuming one uses qcow2 images at all).
  • one cannot yet merge a currently active external snapshot into the original backing image ("blockcommit").

Out of the above reasons, I'm now implementing a script that:

  1. Saves the VM's state and halts it
  2. Sets up a devicemapper snapshot(s) where the VM's disk images and state reside
  3. Resumes the VM
  4. Mount the snapshot(s) of step 2.
  5. Backs up the VM's disk and state (configuration for convenience)
  6. Merges back the snapshot(s).

If I got everything right, this will take consistent backups of VM's with only seconds (if at all, since 1-3 is fast, possibly sub-second) of downtime. Of course, when restoring, the VM will be way in the past, but at least giving me the option of an orderly shutdown/reboot.

Am I missing something with this solution? Or has someone indeed already implemented this?

© Server Fault or respective owner

Related posts about backup

Related posts about virtualization