From c16fa9184dc66b05e8578fe8fb273e49b18b23d9 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Sat, 6 Jun 2020 14:20:10 +0200 Subject: [PATCH] Fixes: ignore disk, restore dir --- debian/changelog | 2 +- vn-vmware.pl | 63 ++++++++++++++++++++++++------------------------ 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/debian/changelog b/debian/changelog index ef06d4e..37da2fd 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -vn-vmware (1.1.24) stable; urgency=low +vn-vmware (1.1.25) stable; urgency=low * Initial Release. diff --git a/vn-vmware.pl b/vn-vmware.pl index a08dad7..339f394 100755 --- a/vn-vmware.pl +++ b/vn-vmware.pl @@ -615,49 +615,44 @@ sub backup_job() { my $backup_job = $config{backup_jobs}{$job}; my @machines = @{$backup_job->{machines}}; - my $default_rotation; + my $rotation_name; if (exists $backup_job->{rotation}) { - $default_rotation = $backup_job->{rotation}; + $rotation_name = $backup_job->{rotation}; } elsif (exists $config{rotation}) { - $default_rotation = $config{rotation}; + $rotation_name = $config{rotation}; + } + + if (defined ($rotation_name)) { + unless (exists $config{rotations}{$rotation_name}) { + die "Rotation '$rotation_name' not defined."; + } + + my $rotation_cfg = $config{rotations}{$rotation_name}; + + if (exists $rotation_cfg->{count}) { + $rotation_count = $rotation_cfg->{count}; + } + if (exists $rotation_cfg->{days}) { + $rotation_days = $rotation_cfg->{days}; + } + if (exists $rotation_cfg->{archive_regex}) { + $archive_regex = $rotation_cfg->{archive_regex}; + $archive_regex = qr/$archive_regex/; + } + if (exists $rotation_cfg->{archive_fn}) { + $archive_fn = $rotation_cfg->{archive_fn}; + } } foreach my $machine (@machines) { eval { - my $rotation_name = $default_rotation; - if (ref($machine) eq 'HASH') { $vm_name = $machine->{name}; $backup_disks = $machine->{disks}; - - if (exists $machine->{rotation}) { - $rotation_name = $machine->{rotation}; - } } else { $vm_name = $machine; - } - - if (defined ($rotation_name)) { - unless (exists $config{rotations}{$rotation_name}) { - die "Rotation '$rotation_name' not defined."; - } - - my $rotation_cfg = $config{rotations}{$rotation_name}; - - if (exists $rotation_cfg->{count}) { - $rotation_count = $rotation_cfg->{count}; - } - if (exists $rotation_cfg->{days}) { - $rotation_days = $rotation_cfg->{days}; - } - if (exists $rotation_cfg->{archive_regex}) { - $archive_regex = $rotation_cfg->{archive_regex}; - $archive_regex = qr/$archive_regex/; - } - if (exists $rotation_cfg->{archive_fn}) { - $archive_fn = $rotation_cfg->{archive_fn}; - } + $backup_disks = undef; } open_machine(); @@ -787,7 +782,10 @@ sub restore_backup() { die "Restore directory doesn't exists: $restore_dir" } - my $tar_command = "tar xz -C \"$restore_dir\""; + my ($end_dir) = fileparse($backup_file, qr/\..*/); + my $tar_dir = "$restore_dir/$end_dir"; + + my $tar_command = "tar xz -C \"$tar_dir\""; if ($backup_file =~ qr/\.gpg$/) { my $gpg_command = "gpg --decrypt --passphrase-file \"$passphrase_file\" --batch --yes \"$backup_file\""; @@ -798,6 +796,7 @@ sub restore_backup() { log_message $tar_command; unless ($test) { + mkdir($tar_dir, 0755); my $tar_status = system($tar_command); unless ($tar_status == 0) { die "An error occurred restoring backup $backup_file";