Sunday, 2 August 2015

Backing Up Virtual Guests

My virtual guests use LVM for disk storage so we can use the snapshot feature to take live backups.

As these are disk image backups they are large but they are quick - a 10gb disk backup took 5 mins - as I have a huge dedicated backup disk for storing them this isn't a problem.
A note about the backup disk, I've formatted it as ext4 without LVM for maximum compatibility. Should the hardware fail I can pop it into another machine, mount up and go.

Here's an example:

First take a snapshot of the logical volume containing the virtual disk:
lvcreate -s --size=1G -n lv_dns_snap /dev/vg_guests/lv_dns
As the snapshot holds disk updates it needs to be large enough to hold all changes during the lifetime of the snapshot. 1GB is plenty for me. The lvs command will show you how much of the space the snapshot is consuming if you want to tune this.

Next take a copy of the snapshot with dd
dd if=/dev/vg_guests/lv_dns_snap of=/backup/dns-backup.dd bs=1M
Experiment with the block size parameter to see what gives best results for you - 1M worked well for me.

We're done so remove the snapshot
lvremove -f /dev/vg_guests/lv_dns_snap
Whilst we're at it we should also copy the guest xml config file from /etc/libvirt/qemu

Should you need to restore the backup, just shut the guest down and copy the disk image back
dd if=/backup/dns-backup.dd of=/dev/vg_guests/lv_dns

1 comment: