create pid file from full path (to enable multiple instances to run in
authordpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Sun, 11 Dec 2005 14:27:45 +0000 (14:27 +0000)
committerdpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Sun, 11 Dec 2005 14:27:45 +0000 (14:27 +0000)
parallel), update backup in eval, and rollback if needed (for partial
backups mostly)

git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/BackupPC/trunk@250 8392b6e1-25fa-0310-8288-cc32f8e212ea

bin/BackupPC_updatedb

index 6c21876..1b254b2 100755 (executable)
@@ -12,6 +12,7 @@ use Time::HiRes qw/time/;
 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;
@@ -24,7 +25,12 @@ $|=1;
 
 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";
@@ -32,8 +38,8 @@ if (my $pid = $pidfile->running ) {
        $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';
 
@@ -533,17 +539,22 @@ foreach my $host_key (@hosts) {
 
                        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",