|
|
|
@ -31,7 +31,6 @@ use Getopt::Long; |
|
|
|
|
umask(022); |
|
|
|
|
|
|
|
|
|
# Some constant |
|
|
|
|
|
|
|
|
|
our %opts = (); |
|
|
|
|
our @vms = (); |
|
|
|
|
our @excludes = (); |
|
|
|
@ -157,6 +156,7 @@ if (($opts{state}) && ($opts{shutdown})){ |
|
|
|
|
exit 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# Backup dir needs to be created first |
|
|
|
|
if (! -d $opts{backupdir} ){ |
|
|
|
|
print "$opts{backupdir} is not a valid directory\n"; |
|
|
|
|
exit 1; |
|
|
|
@ -167,8 +167,6 @@ print "\n\nConnecting to libvirt daemon using $opts{connect} as URI\n" if ($opts |
|
|
|
|
our $libvirt = Sys::Virt->new( uri => $opts{connect} ) || |
|
|
|
|
die "Error connecting to libvirt on URI: $opts{connect}"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print "\n" if ($opts{debug}); |
|
|
|
|
|
|
|
|
|
foreach our $vm (@vms){ |
|
|
|
@ -204,18 +202,19 @@ foreach our $vm (@vms){ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
############################################################################ |
|
|
|
|
############## FUNCTIONS #################### |
|
|
|
|
############################################################################ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Common routine before backup. Will save the XML description, try to |
|
|
|
|
# create a snapshot of the disks etc... |
|
|
|
|
sub prepare_backup{ |
|
|
|
|
# Create a new XML object |
|
|
|
|
my $xml = new XML::Simple (); |
|
|
|
|
my $data = $xml->XMLin( $dom->get_xml_description(), forcearray => ['disk'] ); |
|
|
|
|
|
|
|
|
|
# STop here if the lock file is present, another dump might be running |
|
|
|
|
# Stop here if the lock file is present, another dump might be running |
|
|
|
|
die "Another backup is running\n" if ( -e "$backupdir.meta/$vm.lock" ); |
|
|
|
|
|
|
|
|
|
# Lock VM: Create a lock file so only one dump process can run |
|
|
|
@ -242,7 +241,6 @@ sub prepare_backup{ |
|
|
|
|
|
|
|
|
|
# Create a list of disks used by the VM |
|
|
|
|
foreach $disk (@{$data->{devices}->{disk}}){ |
|
|
|
|
|
|
|
|
|
my $source; |
|
|
|
|
if ($disk->{type} eq 'block'){ |
|
|
|
|
$source = $disk->{source}->{dev}; |
|
|
|
@ -446,7 +444,7 @@ sub run_cleanup{ |
|
|
|
|
print "$cnt file(s) removed\n$snap LVM snapshots removed\n$meta metadata files removed\n\n" if $opts{debug}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Print help |
|
|
|
|
sub usage{ |
|
|
|
|
print "usage:\n$0 --action=[dump|cleanup|chunkmount|unlock] --vm=vm1[,vm2,vm3] [--debug] [--exclude=hda,hdb] [--compress] ". |
|
|
|
|
"[--state] [--shutdown] [--shutdown-timeout] [--no-snapshot] [--snapsize=<size>] [--backupdir=/path/to/dir] [--connect=<URI>] ". |
|
|
|
@ -554,7 +552,6 @@ sub resume_vm(){ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Shutdown a VM via ACPI |
|
|
|
|
sub shutdown_vm(){ |
|
|
|
|
if ($dom->is_active()){ |
|
|
|
|