Don't abort backups when error copying optional files, logging improved
This commit is contained in:
parent
df3051e529
commit
59fcc504e2
|
@ -1,4 +1,4 @@
|
|||
vn-vmware (1.1.3) stable; urgency=low
|
||||
vn-vmware (1.1.4) stable; urgency=low
|
||||
|
||||
* Initial Release.
|
||||
|
||||
|
|
31
vn-vmware.pl
31
vn-vmware.pl
|
@ -416,13 +416,20 @@ sub backup_machine() {
|
|||
'nvram',
|
||||
'log'
|
||||
);
|
||||
my @opt_files = (
|
||||
'log'
|
||||
);
|
||||
|
||||
foreach my $file (@$files) {
|
||||
unless ($file->type ~~ @copy_files) {
|
||||
next;
|
||||
}
|
||||
|
||||
my $file_path = $file->name;
|
||||
my $file_name = basename($file_path);
|
||||
|
||||
if ($file->type ~~ @copy_files) {
|
||||
log_message $file_path;
|
||||
eval {
|
||||
$file_manager->CopyDatastoreFile(
|
||||
sourceName => $file_path,
|
||||
sourceDatacenter => $dc,
|
||||
|
@ -430,6 +437,15 @@ sub backup_machine() {
|
|||
destinationDatacenter => $dc
|
||||
);
|
||||
}
|
||||
|
||||
my $err = $@;
|
||||
if ($err) {
|
||||
if ($file->type ~~ @opt_files) {
|
||||
log_error $err;
|
||||
} else {
|
||||
die $err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log_message "Creating backup snapshot.";
|
||||
|
@ -447,7 +463,7 @@ sub backup_machine() {
|
|||
my $vdm = Vim::get_view(mo_ref => $service_content->virtualDiskManager);
|
||||
|
||||
foreach my $device (@$devices) {
|
||||
if (not($device->isa('VirtualDisk'))) {
|
||||
unless ($device->isa('VirtualDisk')) {
|
||||
next;
|
||||
}
|
||||
|
||||
|
@ -560,19 +576,22 @@ sub rotate_backup() {
|
|||
|
||||
$delete_count = scalar(@delete_files);
|
||||
|
||||
if ($delete_count > 0) {
|
||||
if ($delete_count == $file_count) {
|
||||
die "Rotation aborted, because is trying to remove all backups.";
|
||||
}
|
||||
|
||||
log_message "Removing $delete_count detected old backups.";
|
||||
|
||||
foreach my $deleteFile (@delete_files) {
|
||||
my $deleteFilePath = "$local_dir/$deleteFile";
|
||||
log_message "Removing $deleteFilePath";
|
||||
log_message $deleteFilePath;
|
||||
unlink "$deleteFilePath";
|
||||
}
|
||||
|
||||
if (scalar(@delete_files) == 0) {
|
||||
log_message "No backups to clean.";
|
||||
log_message "Old backups cleaned.";
|
||||
} else {
|
||||
log_message "Total: $delete_count backups cleaned.";
|
||||
log_message "No backups to clean.";
|
||||
}
|
||||
|
||||
closedir($dh);
|
||||
|
|
Reference in New Issue