[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[virt-tools-list] pre/post backup script for KVM guests



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 firewall-services com
Web : http://www.firewall-services.com


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]