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";
}
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);
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;
}
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) {
if ($fh) {
return if ($current_tar_size == 0);
- print STDERR " $part" if ($opts{v});
+ print STDERR " $part";
#
# Finish with two null 512 byte headers,
$items_in_part,
);
- #$total_increment_size += int( ( $size + 1023 ) / 1024 ) * 1024;
$total_increment_size += $size;
if ($arg->{close}) {
}
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}");
}