X-Git-Url: https://oss.titaniummirror.com/gitweb?a=blobdiff_plain;f=BackupPC_ovz;h=2cbc86ca889b79990262893b1e9b41c8d6c37789;hb=23d759720b40018bcfa4c5036b5a5fb2c9496e77;hp=9e92313a6065baa48e27511f9e09ac7054f1b4a6;hpb=ee05bc55bd6c6114eefeb8ced04d86ea054c3215;p=ovzbpc.git diff --git a/BackupPC_ovz b/BackupPC_ovz index 9e92313..2cbc86c 100755 --- a/BackupPC_ovz +++ b/BackupPC_ovz @@ -24,10 +24,13 @@ my $snapsize = '25g'; my $hnlistFile = "/etc/backuppc/".basename($0).".hnlist"; my $velistFile = $ENV{HOME}."/log/".basename($0).".velist"; -# Uncomment one of the following +# Write to the debug file only if it is already present +my $dbgfn = "/tmp/BackupPC_ovz.debug"; my $dbgf; -open $dbgf, ">>/tmp/BackupPC_ovz.debug" || die "Cannot open debug file"; -#open $dbgf, ">>/dev/null" || die "Cannot open debug file"; +if ( ! -f $dbgfn) { + $dbgfn = "/dev/null"; +} +open $dbgf, ">>$dbgfn" || die "Cannot open debug file $dbgfn"; sub mydie($) { @@ -47,7 +50,8 @@ sub cmdExecOrEval print(STDERR "Perl code fragment for exec shouldn't return!!\n"); exit(1); } else { - $cmd = [split(/\s+/, $cmd)] if ( ref($cmd) ne "ARRAY" ); + $cmd = [split(/\s+/, $cmd)] if ( ref($cmd) ne "ARRAY" ); + print $dbgf ": execing command $cmd\n"; alarm(0); $cmd = [map { m/(.*)/ } @$cmd]; # untaint # @@ -68,8 +72,10 @@ sub cmdSystemOrEval $? = 0; $cmd = join(" ", $cmd) if ( ref($cmd) eq "ARRAY" ); if ( (ref($cmd) eq "ARRAY" ? $cmd->[0] : $cmd) =~ /^\&/ ) { + print $dbgf ": evaluating command $cmd\n"; eval($cmd); } else { + print $dbgf ": running command $cmd\n"; system($cmd); } } @@ -435,6 +441,31 @@ sub checkRunningClient() } } +sub runPing() +{ + # This command generates ping output by pinging the host specified in the + # ping command still within @ARGV. However, if the host listed therein is + # a VE, the HN must be pinged instead. + + # Get the host + my $host = shift(@ARGV); + my $cmd = join(' ', @ARGV); + + # Find $host in the list of VEs + loadVeList(); + my $hostname = gethostbyaddr(gethostbyname($host), AF_INET); + mydie "Host $host not found" if (!defined($hostname)); + my $ve = getVeEntry('hostname', $hostname); + if (defined($ve)) { + $hostname = $ve->{'HN'}; + mydie "HN is undefined for host $host" if (!defined($hostname)); + $cmd =~ s/$host/$hostname/g; + print $dbgf ": ping request for $host remapped to HN $hostname\n"; + } + + cmdExecOrEval($cmd); +} + sub runClient($) { my ($restore) = @_; @@ -557,10 +588,21 @@ if ($ARGV[0] eq "restore") { #print "Restore mode\n"; } +my $ping = 0; +if ($ARGV[0] eq "ping") { + shift(@ARGV); + $ping = 1; + #print "Ping mode\n"; +} + +print $dbgf ": server=$server, refresh=$refresh, restore=$restore ping=$ping"; +print $dbgf " on ".`date`; if ($server) { runServer($restore); } elsif ($refresh) { refreshConfig(); +} elsif ($ping) { + runPing(); } else { runClient($restore); }