Friday, April 10, 2015

Backup a KVM host with CrashPlan and LVM snapshots


Backups. Everyone's favorite topic.

You've heard it before. You should back your shit up. I'm sure there are a number of reasons why you aren't backing things up.

I've recently been managing a box with a bunch of virtual machines on it. The virtual machines are of the KVM/libvirt kind so you manage them with the command line tool virsh.

The question is how in the hell do you get a "good" backup solution. I came up with this solution but am welcome to hear how you others do it as well.

I signed up for CrashPlan. Mostly because they support Linux and they are relatively cheap. BackBlaze is good but does not support Linux so they are out.

The general strategy is to "snapshot" the partition where you store all your KVM images and then backup that snapshot.

You must be using LVM. Most Ubuntu installs are using it by default. Doing a df -h you should look for stuff like /dev/mapper which is a tell tale sign you are using it:

root@example:/var/kvm# df -h
Filesystem                          Size  Used Avail Use% Mounted on
/dev/mapper/example--vg-root          832G   48G  742G   7% /

What I do is snapshot the partition with all the images on it. I then point CrashPlan to it and then run this script every so often:


This script recreates the partition so you get a fresh snapshot. Probably not the best situation but it works for me.






2 comments:

Nick Demou said...

You should not leave the snapshot mounted after your backup is done. Otherwise you stress your disks a bit more for no benefit (for almost another 24hours your snapshot keeps growing for no reason).
It's better to keep every guest in it's own lvm logical disk.
You should definitely pause (or shut down) your guests before you keep your snapshot in order to backup consistent/stable data (there's no guarantee that processes that keep complex data open like SQL databases will restart gracefully without data loss/corruption).

Jeff Tchang said...

What if you can't shutdown or pause your guest?