fix parsing of gzip -l output
[BackupPC.git] / bin / BackupPC_ASA_PostArchive_Update
index aff3a0b..11de07e 100755 (executable)
@@ -66,10 +66,7 @@ my $start_t = time();
 
 my $t_fmt = '%Y-%m-%d %H:%M:%S';
 
-warn "## Conf = ",dump( \%Conf );
-
-my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n";
-my $user = $Conf{SearchUser} || '';
+#warn "## Conf = ",dump( \%Conf );
 
 my $dbh = DBI->connect($Conf{SearchDSN}, $Conf{SearchUser}, "", { RaiseError => 1, AutoCommit => 0 });
 
@@ -130,6 +127,14 @@ sub system_ok {
        system(@_) == 0 || die "system @_:$!";
 }
 
+my $sth_inc_size = $dbh->prepare(qq{
+       update backups set
+               inc_size = ?,
+               parts = ?,
+               inc_deleted = false
+       where id = ?
+});
+
 sub check_archive {
        my ($host,$num) = @_;
 
@@ -171,20 +176,21 @@ sub check_archive {
                }
 
                open(my $gzip, $Conf{GzipPath}." -l $filename |") || die "can't gzip -l $filename: $!";
+               local $/ = undef;
                my $line = <$gzip>;
-               chomp($line);
-               $line = <$gzip> if ($line =~ /^\s+compressed/);
+               close($gzip);
 
                my ($comp, $uncomp) = (0,0);
 
-               if ($line =~ m/^\s+(\d+)\s+(\d+)\s+\d+\.\d+/) {
+               if ($line =~ m/\s+(\d+)\s+(\d+)\s+\d+\.\d+/s) {
                        if (wantarray) {
                                return [ $1, $2 ];
                        } else {
                                return $2;
                        }
                } else {
-                       die "can't find size in line: $line";
+                       warn "ERROR can't parse: $line";
+                       return -s $filename;
                }
        }
 
@@ -228,14 +234,14 @@ sub check_archive {
 
        print " [parts: ",join(", ", @tar_parts),"]" if $debug;
 
-       my $same = 1;
        my @tar_files;
 
        my $backup_part;
 
        print " reading" if $debug;
 
-       my $part_nr = 1;
+       my $part_nr = 0;
+       my $inc_size = 0;
 
        foreach my $filename (@tar_parts) {
 
@@ -302,14 +308,20 @@ sub check_archive {
 
                my $md5 = $md5sum->{$filename} || die "no md5sum for $filename in ",dump($md5sum);
                my $items = 1;
+               $part_nr++;
 
                check_part($host, $num, $part_nr, $tar_size, $size, $md5, $items);
 
-               $part_nr++;
+               # round increment size to 2k block size
+               $inc_size += int(($size + 2048) / 2048);
        }
 
-       # short-cut and exit;
-       return $same unless($same);
+       $sth_inc_size->execute(
+               $inc_size,
+               $part_nr,
+               get_backup_id($host, $num),
+       );
+       $dbh->commit;
 
        @tar_files = sort @tar_files;
        print "\n\t",($#tar_files + 1), " tar files";
@@ -335,6 +347,8 @@ sub check_archive {
 
        @db_files = sort @db_files;
 
+       my $same = 1;
+
        if ($#tar_files != $#db_files) {
                $same = 0;
                print " NUMBER";