BackupPC-users

[BackupPC-users] pre/post backup script for KVM guests

2009-10-19 09:10:43
Subject: [BackupPC-users] pre/post backup script for KVM guests
From: Daniel Berteaud <daniel AT firewall-services DOT com>
To: virt-tools-list AT redhat DOT com, backuppc-users AT lists.sourceforge DOT net
Date: Mon, 19 Oct 2009 15:02:58 +0200
Hi everyone.

I've written a script to backup virtual machines managed by libvirt
(only tested with KVM guests, but should works for Xen too, maybe others
as well).

It's called virt-backup.pl

I've written it for integration with BackupPC:
- take a dump of a VM in using the pre-backup facility
- backup the dumps using BackupPC
- cleanup the dumps in the post-backup phase

This script can be used outside of BackupPC as it's quite generic.

There are two main mode for this script:
--pre: take the backup of the VM. This is called --pre because I use it
as a pre-backup script for BackupPC
--post: cleanup the dumps

Here're some functionalities:

- no configuration file needed, everything can be passed as command line
arg
- can take snapshots of virtual disks if they are on LVM Logical volume
(the default is to try LVM in any case, if it's not possible, then, just
dump the block device/file)
- Supports backup of running VM with minimal downtime (if each virtual
disks can be snapshoted, just resume the VM immediately resulting in
just a few seconds of downtime, then, dump the snapshots. If snapshots
are not available, the guest is suspended during the dump)
- can save the state of running vm (equivalent of virsh save/virsh
restore). This is optional because it's still not very reliable, and
sometimes the restoration fails, leaving a crashed qemu process running
and eating CPU cycles.
- Can compress on-the-fly the virtual disks dumps
(gzip,bzip2,pbzip2,lzop,xz)
- Support virtual disks exclusions (if you want to backup the system
disk of a VM, but not the data one for example)
- Can work on installations where virtual disks are stored on one hosts,
and guests runs on another on (NFS, iscsi etc... in any case, the script
must be run on the host which holds the virtual disks)
- Can backup as many guests as you want in one run (they'll be dumped
sequentially)
- Backups are run with low priority (nice and ionice), so it should'nt
slow down too much your system.

Here are the dependencies for this script to work
- Sys::Virt perl module
- XML::Simple per module
- Getopt::Long perl module
- lvm2
- gzip (optional)
- bzip2 (optional)
- pbzip2 (optional)
- lzop (optional)
- xz (optional)

You can run this script without argument to see the help. Edit it if you
want more informations (there are some examples on how to use it at the
beginning of the script).


The script can be found here:

http://repo.firewall-services.com/misc/virt-backup.pl

Regards, Daniel

-- 
Daniel Berteaud
FIREWALL-SERVICES SARL.
Société de Services en Logiciels Libres
Technopôle Montesquieu
33650 MARTILLAC
Tel : 05 56 64 15 32
Fax : 05 56 64 15 32
Mail: daniel AT firewall-services DOT com
Web : http://www.firewall-services.com


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
BackupPC-users mailing list
BackupPC-users AT lists.sourceforge DOT net
List:    https://lists.sourceforge.net/lists/listinfo/backuppc-users
Wiki:    http://backuppc.wiki.sourceforge.net
Project: http://backuppc.sourceforge.net/
<Prev in Thread] Current Thread [Next in Thread>