use File::Pid;
use POSIX qw/strftime/;
use BackupPC::SearchLib;
+use Cwd qw/abs_path/;
use constant BPC_FTYPE_DIR => 5;
use constant EST_CHUNK => 100000;
my $start_t = time();
-my $pidfile = new File::Pid;
+my $pid_path = abs_path($0);
+$pid_path =~ s/\W+/_/g;
+
+my $pidfile = new File::Pid({
+ file => "/tmp/$pid_path",
+});
if (my $pid = $pidfile->running ) {
die "$0 already running: $pid\n";
$pidfile->remove;
$pidfile = new File::Pid;
}
-$pidfile->write;
print STDERR "$0 using pid ",$pidfile->pid," file ",$pidfile->file,"\n";
+$pidfile->write;
my $t_fmt = '%Y-%m-%d %H:%M:%S';
my $skip_check = $opt{j} && print STDERR "Skipping check for existing files -- this should be used only with initital import\n";
- unless ($use_hest) {
+ unless (defined($use_hest)) {
print STDERR "HyperEstraier support not enabled in configuration\n";
+ $use_hest = 0;
return;
}
+ return unless($use_hest);
+
print curr_time," updating HyperEstraier:";
my $t = time();
VALUES (?,?,?,?,?,?,?)
});
-foreach my $host_key (keys %{$hosts}) {
+my @hosts = keys %{$hosts};
+my $host_nr = 0;
+
+foreach my $host_key (@hosts) {
my $hostname = $hosts->{$host_key}->{'host'} || die "can't find host for $host_key";
$hostID = $dbh->last_insert_id(undef,undef,'hosts',undef);
}
- print "host ".$hosts->{$host_key}->{'host'}.": ";
+ $host_nr++;
+ print "host ", $hosts->{$host_key}->{'host'}, " [",
+ $host_nr, "/", ($#hosts + 1), "]: ";
# get backups for a host
my @backups = $bpc->BackupInfoRead($hostname);
my ($f, $nf, $d, $nd, $size) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID);
- $sth->{update_backups_size}->execute(
- $size,
- $hostID,
- $backupNum,
- $backup->{'endTime'},
- substr($backup->{'type'},0,4),
- $shareID,
- );
-
- print " commit";
- $dbh->commit();
+ eval {
+ $sth->{update_backups_size}->execute(
+ $size,
+ $hostID,
+ $backupNum,
+ $backup->{'endTime'},
+ substr($backup->{'type'},0,4),
+ $shareID,
+ );
+ print " commit";
+ $dbh->commit();
+ };
+ if ($@) {
+ print " rollback";
+ $dbh->rollback();
+ }
my $dur = (time() - $t) || 1;
printf(" %d/%d files %d/%d dirs %0.2f MB [%.2f/s dur: %s]\n",