|
|
@ -31,7 +31,6 @@ use Getopt::Long; |
|
|
|
umask(022); |
|
|
|
umask(022); |
|
|
|
|
|
|
|
|
|
|
|
# Some constant |
|
|
|
# Some constant |
|
|
|
|
|
|
|
|
|
|
|
our %opts = (); |
|
|
|
our %opts = (); |
|
|
|
our @vms = (); |
|
|
|
our @vms = (); |
|
|
|
our @excludes = (); |
|
|
|
our @excludes = (); |
|
|
@ -157,6 +156,7 @@ if (($opts{state}) && ($opts{shutdown})){ |
|
|
|
exit 1; |
|
|
|
exit 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Backup dir needs to be created first |
|
|
|
if (! -d $opts{backupdir} ){ |
|
|
|
if (! -d $opts{backupdir} ){ |
|
|
|
print "$opts{backupdir} is not a valid directory\n"; |
|
|
|
print "$opts{backupdir} is not a valid directory\n"; |
|
|
|
exit 1; |
|
|
|
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} ) || |
|
|
|
our $libvirt = Sys::Virt->new( uri => $opts{connect} ) || |
|
|
|
die "Error connecting to libvirt on URI: $opts{connect}"; |
|
|
|
die "Error connecting to libvirt on URI: $opts{connect}"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print "\n" if ($opts{debug}); |
|
|
|
print "\n" if ($opts{debug}); |
|
|
|
|
|
|
|
|
|
|
|
foreach our $vm (@vms){ |
|
|
|
foreach our $vm (@vms){ |
|
|
@ -204,18 +202,19 @@ foreach our $vm (@vms){ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
############################################################################ |
|
|
|
############################################################################ |
|
|
|
############## FUNCTIONS #################### |
|
|
|
############## FUNCTIONS #################### |
|
|
|
############################################################################ |
|
|
|
############################################################################ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Common routine before backup. Will save the XML description, try to |
|
|
|
|
|
|
|
# create a snapshot of the disks etc... |
|
|
|
sub prepare_backup{ |
|
|
|
sub prepare_backup{ |
|
|
|
# Create a new XML object |
|
|
|
# Create a new XML object |
|
|
|
my $xml = new XML::Simple (); |
|
|
|
my $xml = new XML::Simple (); |
|
|
|
my $data = $xml->XMLin( $dom->get_xml_description(), forcearray => ['disk'] ); |
|
|
|
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" ); |
|
|
|
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 |
|
|
|
# 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 |
|
|
|
# Create a list of disks used by the VM |
|
|
|
foreach $disk (@{$data->{devices}->{disk}}){ |
|
|
|
foreach $disk (@{$data->{devices}->{disk}}){ |
|
|
|
|
|
|
|
|
|
|
|
my $source; |
|
|
|
my $source; |
|
|
|
if ($disk->{type} eq 'block'){ |
|
|
|
if ($disk->{type} eq 'block'){ |
|
|
|
$source = $disk->{source}->{dev}; |
|
|
|
$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 "$cnt file(s) removed\n$snap LVM snapshots removed\n$meta metadata files removed\n\n" if $opts{debug}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Print help |
|
|
|
sub usage{ |
|
|
|
sub usage{ |
|
|
|
print "usage:\n$0 --action=[dump|cleanup|chunkmount|unlock] --vm=vm1[,vm2,vm3] [--debug] [--exclude=hda,hdb] [--compress] ". |
|
|
|
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>] ". |
|
|
|
"[--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 |
|
|
|
# Shutdown a VM via ACPI |
|
|
|
sub shutdown_vm(){ |
|
|
|
sub shutdown_vm(){ |
|
|
|
if ($dom->is_active()){ |
|
|
|
if ($dom->is_active()){ |
|
|
|