Bug fixes
This commit is contained in:
parent
c88562c708
commit
0997e8cf80
|
@ -26,13 +26,13 @@ local_backup_dir => '/mnt/vm-backups',
|
||||||
backup_jobs => {
|
backup_jobs => {
|
||||||
schedule1 => {
|
schedule1 => {
|
||||||
machines => ['test'],
|
machines => ['test'],
|
||||||
rotation => 'daily'
|
rotation => 'lastMonth'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
# Backup rotation configuration
|
# Backup rotation configuration
|
||||||
rotations => {
|
rotations => {
|
||||||
daily => {
|
lastMonth => {
|
||||||
days => 31,
|
days => 31,
|
||||||
count => 31
|
count => 31
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
MAILFROM="bacula@verdnatura.es"
|
MAILFROM="bacula@verdnatura.es"
|
||||||
MAILTO="sysadmin@verdnatura.es"
|
MAILTO="sysadmin@verdnatura.es"
|
||||||
|
|
||||||
30 21 * * * root vn-vmware.pl --operation clone-job --job testDb
|
00 03 * * tue-fri root vn-vmware.pl --operation clone-job --job testDb
|
||||||
01 01 02 * * root vn-vmware.pl --operation clone-job --job monthlyDb
|
00 02 01 * * root vn-vmware.pl --operation clone-job --job monthlyDb
|
||||||
|
|
||||||
00 04 * * * root vn-vmware.pl --operation backup-job --job db
|
00 04 * * * root vn-vmware.pl --operation backup-job --job db
|
||||||
00 01 * * sat root vn-vmware.pl --operation backup-job --job friday
|
00 01 * * sat root vn-vmware.pl --operation backup-job --job friday
|
||||||
|
|
36
vn-vmware.pl
36
vn-vmware.pl
|
@ -42,8 +42,8 @@ my %opts = (
|
||||||
},
|
},
|
||||||
'rotation-count' => {
|
'rotation-count' => {
|
||||||
type => "=i",
|
type => "=i",
|
||||||
help => "Number of backups to keep despite the rotation",
|
help => "Number of backups to keep despite the rotation days",
|
||||||
default => 5
|
default => 0
|
||||||
},
|
},
|
||||||
'dst-name' => {
|
'dst-name' => {
|
||||||
type => "=s",
|
type => "=s",
|
||||||
|
@ -303,16 +303,29 @@ sub backup_job() {
|
||||||
|
|
||||||
my $backup_job = $config{backup_jobs}{$job};
|
my $backup_job = $config{backup_jobs}{$job};
|
||||||
|
|
||||||
my $rotation_cfg = $config{rotations}{$backup_job->{rotation}};
|
if (exists $backup_job->{rotation}) {
|
||||||
|
my $rotation_name = $backup_job->{rotation};
|
||||||
|
|
||||||
|
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};
|
$rotation_count = $rotation_cfg->{count};
|
||||||
|
}
|
||||||
|
if (exists $rotation_cfg->{days}) {
|
||||||
$rotation_days = $rotation_cfg->{days};
|
$rotation_days = $rotation_cfg->{days};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
my @machines = @{$backup_job->{machines}};
|
my @machines = @{$backup_job->{machines}};
|
||||||
|
|
||||||
foreach my $machine (@machines) {
|
foreach my $machine (@machines) {
|
||||||
eval {
|
eval {
|
||||||
$vm_name = $machine;
|
$vm_name = $machine;
|
||||||
&open_machine();
|
open_machine();
|
||||||
backup_machine();
|
backup_machine();
|
||||||
rotate_backup();
|
rotate_backup();
|
||||||
};
|
};
|
||||||
|
@ -422,12 +435,17 @@ sub backup_machine() {
|
||||||
$vm->RemoveAllSnapshots();
|
$vm->RemoveAllSnapshots();
|
||||||
|
|
||||||
log_message "Compressing to TAR file: $tar_file";
|
log_message "Compressing to TAR file: $tar_file";
|
||||||
system("tar -I pigz -cf $tar_file -C $local_tmp_dir .");
|
my $tar_status = system("tar -I pigz -cf $tar_file -C $local_tmp_dir .");
|
||||||
|
|
||||||
|
unless ($tar_status == 0) {
|
||||||
|
die "An error occurred when trying to compress the file."
|
||||||
|
}
|
||||||
};
|
};
|
||||||
my $err = $@;
|
my $err = $@;
|
||||||
|
|
||||||
if ($err) {
|
if ($err) {
|
||||||
log_error "An error ocurred during '$vm_name' backup, aborting."
|
log_message "An error ocurred during '$vm_name' backup, aborting.";
|
||||||
|
$vm->RemoveAllSnapshots();
|
||||||
}
|
}
|
||||||
|
|
||||||
log_message "Removing temporary directory: $local_tmp_dir";
|
log_message "Removing temporary directory: $local_tmp_dir";
|
||||||
|
@ -538,15 +556,15 @@ sub clone_machine {
|
||||||
}
|
}
|
||||||
|
|
||||||
my $relocate_spec;
|
my $relocate_spec;
|
||||||
my $mac_type = "Generated";
|
my $mac_type = 'Generated';
|
||||||
my $host_view = $vm->summary->runtime->host;
|
my $host_view = $vm->summary->runtime->host;
|
||||||
|
|
||||||
if (defined($mac)) {
|
if (defined($mac)) {
|
||||||
$mac_type = "Manual"
|
$mac_type = 'Manual';
|
||||||
}
|
}
|
||||||
if (defined ($dst_host)) {
|
if (defined ($dst_host)) {
|
||||||
$host_view = Vim::find_entity_view(
|
$host_view = Vim::find_entity_view(
|
||||||
view_type => "HostSystem",
|
view_type => 'HostSystem',
|
||||||
filter => {'name' => $dst_host}
|
filter => {'name' => $dst_host}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue