Improved fault tolerance & logging

This commit is contained in:
Juan 2018-08-26 15:12:26 +02:00
parent 42ad086d6a
commit 2e18e252b4
2 changed files with 11 additions and 6 deletions

2
debian/changelog vendored
View File

@ -1,4 +1,4 @@
vn-vmware (1.0.18) stable; urgency=low
vn-vmware (1.0.19) stable; urgency=low
* Initial Release.

View File

@ -11,7 +11,6 @@ use VMware::VIExt;
use Time::Piece;
use Time::Seconds;
use File::Path;
use Net::OpenSSH;
use Sys::CPU;
use Term::ANSIColor;
use IO::Handle;
@ -220,7 +219,6 @@ if ($log_fh) {
}
sub main {
my $vcenter_host = $config{hostname};
my $username = $config{user};
@ -399,6 +397,10 @@ sub backup_machine() {
);
eval {
if (-e $local_tmp_dir) {
die "Local backup directory is not accessible: $local_tmp_dir";
}
my $vm_path_name = $vm->config->files->vmPathName;
log_message "Copying machine configuration file: $vm_path_name";
@ -455,7 +457,7 @@ sub backup_machine() {
my $tar_status = system($tar_command);
unless ($tar_status == 0) {
die "An error occurred when trying to compress the file.";
die "An error occurred when trying to compress '$vm_name' machine files.";
}
};
my $err = $@;
@ -467,8 +469,11 @@ sub backup_machine() {
$vm->RemoveAllSnapshots();
}
log_message "Removing temporary directory: $local_tmp_dir";
rmtree($local_tmp_dir);
log_message "Removing temporary directory: $ds_tmp_dir";
$file_manager->DeleteDatastoreFile(
name => $ds_tmp_dir,
datacenter => $dc
);
if ($err) {
die $err;