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 ($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",