Merge branch 'search-3.2.0' of git.rot13.org:/git/BackupPC into search-3.2.0
[BackupPC.git] / bin / BackupPC_ASA_PostArchive_Update
index 93478c9..e70bfb1 100755 (executable)
@@ -38,6 +38,7 @@ my ($opt,$usage) = describe_options(
 "%c %o",
 [ 'host|h=s@', "import just host(s)" ],
 [ 'num|n=s@',  "import just backup number(s)" ],
+[ 'ok=n',       "xferOK", { default => 0 } ],
 [ 'check|c',   "check archives on disk and sync", { default => 1 } ],
 [ 'debug|d',   "debug", { default => 1 } ],
 [ 'help',      "show help" ],
@@ -230,7 +231,6 @@ sub check_archive {
                });
 
                $sth_insert->execute($backup_id, $part_nr, $tar_size, $size, $md5, $items, $filename);
-               $dbh->commit;
        }
 
        print " [parts: ",join(", ", @tar_parts),"]" if $opt->debug;
@@ -322,7 +322,6 @@ sub check_archive {
                $part_nr,
                get_backup_id($host, $num),
        );
-       $dbh->commit;
 
        @tar_files = sort @tar_files;
        print "\n\t",($#tar_files + 1), " tar files";
@@ -366,6 +365,8 @@ sub check_archive {
        print " ",($same ? 'ok' : 'DIFFERENT'),
                ", dur: ",fmt_time(time() - $t), "\n";
 
+       $dbh->commit;
+
        return $same;
 }
 
@@ -374,10 +375,18 @@ sub check_archive {
 
 foreach ( 0 .. $#{ $opt->host } ) {
 
-       my $host = $opt->host->[$_];
+       my $host = lc $opt->host->[$_];
        my $num  = $opt->num->[$_];
 
-       check_archive $host => $num;
+       if ( ! $opt->ok ) {
+               warn "ERROR $host $num running cleanup";
+               foreach my $path ( glob "$Conf{ArchiveDest}/$host.$num.*" ) {
+                       warn "# rm $path";
+                       unlink $path || die $!;
+               }
+       } else {
+               check_archive $host => $num;
+       }
 
 }
 
@@ -446,8 +455,6 @@ while (my $row = $sth->fetchrow_hashref) {
 
        print ", dur: ",fmt_time(time() - $t), "\n";
 
-       $dbh->commit;
-
 }
 
 undef $sth;