r11640@llin: dpavlin | 2005-12-12 18:07:17 +0100
authordpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Mon, 12 Dec 2005 16:07:27 +0000 (16:07 +0000)
committerdpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Mon, 12 Dec 2005 16:07:27 +0000 (16:07 +0000)
 tar_check works again and creates missing md5 sum files (if needed)

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

bin/BackupPC_incPartsUpdate
bin/BackupPC_tarIncCreate
lib/BackupPC/SearchLib.pm

index 517acc2..ef49d1f 100755 (executable)
@@ -32,7 +32,7 @@ my $tarIncCreate = $path .= 'BackupPC_tarIncCreate';
 die "can't find $tarIncCreate: $!\n" unless (-x $tarIncCreate);
 
 my $bin;
-foreach my $c (qw/gzip/) {
+foreach my $c (qw/gzip md5sum/) {
        $bin->{$c} = which($c) || die "$0 needs $c, install it\n";
 }
 
@@ -75,29 +75,50 @@ sub curr_time {
 sub tar_check($$$$) {
        my ($host,$share,$num,$filename) = @_;
 
-       return 1;       # FIXME
-
        if ($debug) {
                print STDERR " {{ CHECK: ${host}:${share}#${num} and $filename";
        } else {
                print " check";
        }
 
-       if (-d $filename) {
-               print STDERR ", joining";
-               tar_join($filename);
-       }
+       my @tar_parts;
 
-       print STDERR ", opening" if ($debug);
-       open(my $fh, "gzip -cd $filename |") or die "can't open $filename: $!";
-       binmode($fh);
-       my $tar = Archive::Tar::Streamed->new($fh);
+       if (-d "$tar_dir/$filename") {
+               print STDERR " multi-part" if ($opt{d});
+               opendir(my $dir, "$tar_dir/$filename") || die "can't readdir $tar_dir/$filename: $!";
+               @tar_parts = map { my $p = $_; $p =~ s#^#${filename}/#; $p } grep { !/^\./ && !/md5/ && -f "$tar_dir/$filename/$_" } readdir($dir);
+               closedir($dir);
+       } else {
+               push @tar_parts, "${filename}.tar.gz";
+       }
 
-       print STDERR ", tar" if ($debug);
        my @tar_files;
-       while(my $entry = $tar->next) {
-               push @tar_files, $entry->name;
+
+       print " [parts: ",join(", ", @tar_parts),"]" if ($opt{d});
+
+       print " reading";
+
+       foreach my $tarfilename (@tar_parts) {
+
+               print STDERR " $tarfilename" if ($debug);
+
+               my $path = "$tar_dir/$tarfilename";
+               my $md5 = $path;
+               $md5 =~ s/\.tar\.gz$/.md5/ || die "can't create md5 filename from $md5";
+               if (! -e $md5) {
+                       print ", creating md5";
+                       system( $bin->{md5sum} . " $path > $md5") == 0 or die "can't create md5 $path: $!";
+               }
+
+               open(my $fh, "gzip -cd $tar_dir/$tarfilename |") or die "can't open $tar_dir/$tarfilename: $!";
+               binmode($fh);
+               my $tar = Archive::Tar::Streamed->new($fh);
+
+               while(my $entry = $tar->next) {
+                       push @tar_files, $entry->name;
+               }
        }
+
        @tar_files = sort @tar_files;
        print STDERR " ",($#tar_files + 1), " files" if ($debug);
 
@@ -177,7 +198,7 @@ while (my $row = $sth->fetchrow_hashref) {
 
        print "# size: $size backup.size: ", $row->{inc_size},"\n" if ($opt{d});
 
-       if ( $row->{'inc_size'} != -1 && $size != -1 && $row->{'inc_size'} == $size && ( $check && tar_check($row->{'host'}, $row->{'share'}, $row->{'num'}, "$tar_dir/$tar_file") || 1) ) {
+       if ( $row->{'inc_size'} != -1 && $size != -1 && $row->{'inc_size'} == $size && ( $check && tar_check($row->{'host'}, $row->{'share'}, $row->{'num'}, $tar_file) || 1) ) {
                next;
        }
 
@@ -187,7 +208,7 @@ while (my $row = $sth->fetchrow_hashref) {
        my $t = time();
 
        # re-create archive?
-       my $cmd = qq{ $tarIncCreate -h "$row->{'host'}" -s "$row->{'share'}" -n $row->{'num'} };
+       my $cmd = qq{ $tarIncCreate -h "$row->{'host'}" -s "$row->{'share'}" -n $row->{'num'} -f };
        print STDERR "## $cmd\n" if ($debug);
 
        if (system($cmd) != 0) {
index f9ac5cb..9b9d39b 100755 (executable)
@@ -244,7 +244,7 @@ sub new_tar_part {
        if ($fh) {
                return if ($current_tar_size == 0);
 
-               print STDERR " $part" if ($opts{v});
+               print STDERR " $part";
 
                #
                # Finish with two null 512 byte headers,
@@ -272,7 +272,6 @@ sub new_tar_part {
                        $items_in_part,
                );
 
-               #$total_increment_size += int( ( $size + 1023 ) / 1024 ) * 1024;
                $total_increment_size += $size;
 
                if ($arg->{close}) {
@@ -284,12 +283,12 @@ sub new_tar_part {
                        }
 
                        if ($part == 1) {
-                               print STDERR " single";
+                               print STDERR " single" if ($opts{v});
                                move("${tar_path}/1.tar.gz", "${tar_path_final}.tar.gz");
                                move("${tar_path}/1.md5", "${tar_path_final}.md5");
                                rmtree $tar_path or die "can't remove temporary dir $tar_path: $!";
                        } else {
-                               print STDERR " [last]";
+                               print STDERR " [last]" if ($opts{v});
                                move("${tar_path}", "${tar_path_final}");
                        }
 
index 8aa0e12..718fac5 100644 (file)
@@ -381,12 +381,14 @@ sub get_tgz_size_by_name($) {
                $size = (stat("${tgz}.tar.gz"))[7];
        } elsif (-d $tgz) {
                opendir(my $dir, $tgz) || die "can't opendir $tgz: $!";
-               my @parts = grep { !/^\./ && -f "$tgz/$_" } readdir($dir);
+               my @parts = grep { !/^\./ && !/md5/ && -f "$tgz/$_" } readdir($dir);
                $size = 0;
                foreach my $part (@parts) {
                        $size += (stat("$tgz/$part"))[7] || die "can't stat $tgz/$part: $!";
                }
                closedir $dir;
+       } else {
+               return -1;
        }
 
        return $size;