Improved fault tolerance & logging
This commit is contained in:
parent
42ad086d6a
commit
2e18e252b4
|
@ -1,4 +1,4 @@
|
||||||
vn-vmware (1.0.18) stable; urgency=low
|
vn-vmware (1.0.19) stable; urgency=low
|
||||||
|
|
||||||
* Initial Release.
|
* Initial Release.
|
||||||
|
|
||||||
|
|
15
vn-vmware.pl
15
vn-vmware.pl
|
@ -11,7 +11,6 @@ use VMware::VIExt;
|
||||||
use Time::Piece;
|
use Time::Piece;
|
||||||
use Time::Seconds;
|
use Time::Seconds;
|
||||||
use File::Path;
|
use File::Path;
|
||||||
use Net::OpenSSH;
|
|
||||||
use Sys::CPU;
|
use Sys::CPU;
|
||||||
use Term::ANSIColor;
|
use Term::ANSIColor;
|
||||||
use IO::Handle;
|
use IO::Handle;
|
||||||
|
@ -220,7 +219,6 @@ if ($log_fh) {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub main {
|
sub main {
|
||||||
|
|
||||||
my $vcenter_host = $config{hostname};
|
my $vcenter_host = $config{hostname};
|
||||||
my $username = $config{user};
|
my $username = $config{user};
|
||||||
|
|
||||||
|
@ -399,6 +397,10 @@ sub backup_machine() {
|
||||||
);
|
);
|
||||||
|
|
||||||
eval {
|
eval {
|
||||||
|
if (-e $local_tmp_dir) {
|
||||||
|
die "Local backup directory is not accessible: $local_tmp_dir";
|
||||||
|
}
|
||||||
|
|
||||||
my $vm_path_name = $vm->config->files->vmPathName;
|
my $vm_path_name = $vm->config->files->vmPathName;
|
||||||
log_message "Copying machine configuration file: $vm_path_name";
|
log_message "Copying machine configuration file: $vm_path_name";
|
||||||
|
|
||||||
|
@ -455,7 +457,7 @@ sub backup_machine() {
|
||||||
my $tar_status = system($tar_command);
|
my $tar_status = system($tar_command);
|
||||||
|
|
||||||
unless ($tar_status == 0) {
|
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 = $@;
|
my $err = $@;
|
||||||
|
@ -467,8 +469,11 @@ sub backup_machine() {
|
||||||
$vm->RemoveAllSnapshots();
|
$vm->RemoveAllSnapshots();
|
||||||
}
|
}
|
||||||
|
|
||||||
log_message "Removing temporary directory: $local_tmp_dir";
|
log_message "Removing temporary directory: $ds_tmp_dir";
|
||||||
rmtree($local_tmp_dir);
|
$file_manager->DeleteDatastoreFile(
|
||||||
|
name => $ds_tmp_dir,
|
||||||
|
datacenter => $dc
|
||||||
|
);
|
||||||
|
|
||||||
if ($err) {
|
if ($err) {
|
||||||
die $err;
|
die $err;
|
||||||
|
|
Reference in New Issue