22 |
use BackupPC::SearchLib; |
use BackupPC::SearchLib; |
23 |
%BackupPC::SearchLib::Conf = %Conf; |
%BackupPC::SearchLib::Conf = %Conf; |
24 |
|
|
|
# cludge: minimum .tar.gz size |
|
|
my $MIN_TAR_SIZE = 80; |
|
|
|
|
25 |
my $path = abs_path($0); |
my $path = abs_path($0); |
26 |
$path =~ s#/[^/]+$#/#; |
$path =~ s#/[^/]+$#/#; |
27 |
my $tarIncCreate = $path .= 'BackupPC_tarIncCreate'; |
my $tarIncCreate = $path .= 'BackupPC_tarIncCreate'; |
29 |
die "can't find $tarIncCreate: $!\n" unless (-x $tarIncCreate); |
die "can't find $tarIncCreate: $!\n" unless (-x $tarIncCreate); |
30 |
|
|
31 |
my $bin; |
my $bin; |
32 |
foreach my $c (qw/gzip/) { |
foreach my $c (qw/gzip md5sum/) { |
33 |
$bin->{$c} = which($c) || die "$0 needs $c, install it\n"; |
$bin->{$c} = which($c) || die "$0 needs $c, install it\n"; |
34 |
} |
} |
35 |
|
|
72 |
sub tar_check($$$$) { |
sub tar_check($$$$) { |
73 |
my ($host,$share,$num,$filename) = @_; |
my ($host,$share,$num,$filename) = @_; |
74 |
|
|
|
return 1; # FIXME |
|
|
|
|
75 |
if ($debug) { |
if ($debug) { |
76 |
print STDERR " {{ CHECK: ${host}:${share}#${num} and $filename"; |
print STDERR " {{ CHECK: ${host}:${share}#${num} and $filename"; |
77 |
} else { |
} else { |
78 |
print " check"; |
print " check"; |
79 |
} |
} |
80 |
|
|
81 |
if (-d $filename) { |
my @tar_parts; |
82 |
print STDERR ", joining"; |
|
83 |
tar_join($filename); |
if (-d "$tar_dir/$filename") { |
84 |
|
print STDERR " multi-part" if ($opt{d}); |
85 |
|
opendir(my $dir, "$tar_dir/$filename") || die "can't readdir $tar_dir/$filename: $!"; |
86 |
|
@tar_parts = map { my $p = $_; $p =~ s#^#${filename}/#; $p } grep { !/^\./ && !/md5/ && -f "$tar_dir/$filename/$_" } readdir($dir); |
87 |
|
closedir($dir); |
88 |
|
} else { |
89 |
|
push @tar_parts, "${filename}.tar.gz"; |
90 |
} |
} |
91 |
|
|
92 |
print STDERR ", opening" if ($debug); |
print " [parts: ",join(", ", @tar_parts),"]" if ($opt{d}); |
|
open(my $fh, "gzip -cd $filename |") or die "can't open $filename: $!"; |
|
|
binmode($fh); |
|
|
my $tar = Archive::Tar::Streamed->new($fh); |
|
93 |
|
|
94 |
print STDERR ", tar" if ($debug); |
my $same = 1; |
95 |
my @tar_files; |
my @tar_files; |
96 |
while(my $entry = $tar->next) { |
|
97 |
push @tar_files, $entry->name; |
print " reading"; |
98 |
|
|
99 |
|
foreach my $tarfilename (@tar_parts) { |
100 |
|
|
101 |
|
print STDERR " $tarfilename" if ($debug); |
102 |
|
|
103 |
|
my $path = "$tar_dir/$tarfilename"; |
104 |
|
my $md5 = $path; |
105 |
|
$md5 =~ s/\.tar\.gz$/.md5/ || die "can't create md5 filename from $md5"; |
106 |
|
if (! -e $md5) { |
107 |
|
print ", creating md5"; |
108 |
|
system( $bin->{md5sum} . " $path > $md5") == 0 or die "can't create md5 $path: $!"; |
109 |
|
} |
110 |
|
|
111 |
|
open(my $fh, "gzip -cd $tar_dir/$tarfilename |") or die "can't open $tar_dir/$tarfilename: $!"; |
112 |
|
binmode($fh); |
113 |
|
my $tar = Archive::Tar::Streamed->new($fh); |
114 |
|
|
115 |
|
my $total_size = 0; |
116 |
|
|
117 |
|
while(my $entry = $tar->next) { |
118 |
|
push @tar_files, $entry->name; |
119 |
|
$total_size += $entry->size; |
120 |
|
} |
121 |
|
|
122 |
|
if ($total_size > $Conf{MaxArchiveFileSize}) { |
123 |
|
print STDERR " part too big $total_size > $Conf{MaxArchiveFileSize} }}" if ($debug); |
124 |
|
$same = 0; |
125 |
|
last; |
126 |
|
} elsif ($total_size > $Conf{MaxArchiveSize}) { |
127 |
|
print STDERR " part bigger than media $total_size > $Conf{MaxArchiveSize} }}" if ($debug); |
128 |
|
$same = 0; |
129 |
|
last; |
130 |
|
} |
131 |
} |
} |
132 |
|
|
133 |
|
# short-cut and exit; |
134 |
|
return $same unless($same); |
135 |
|
|
136 |
@tar_files = sort @tar_files; |
@tar_files = sort @tar_files; |
137 |
print STDERR " ",($#tar_files + 1), " files" if ($debug); |
print STDERR " ",($#tar_files + 1), " files" if ($debug); |
138 |
|
|
159 |
|
|
160 |
@db_files = sort @db_files; |
@db_files = sort @db_files; |
161 |
|
|
|
my $same = 1; |
|
162 |
if ($#tar_files != $#db_files) { |
if ($#tar_files != $#db_files) { |
163 |
$same = 0; |
$same = 0; |
164 |
print STDERR " NUMBER" if ($debug); |
print STDERR " NUMBER" if ($debug); |
211 |
|
|
212 |
print "# size: $size backup.size: ", $row->{inc_size},"\n" if ($opt{d}); |
print "# size: $size backup.size: ", $row->{inc_size},"\n" if ($opt{d}); |
213 |
|
|
214 |
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) { |
215 |
next; |
if ($check) { |
216 |
|
tar_check($row->{'host'}, $row->{'share'}, $row->{'num'}, $tar_file) && next; |
217 |
|
} else { |
218 |
|
next; |
219 |
|
} |
220 |
} |
} |
221 |
|
|
222 |
print curr_time, " $curr_backup/$num_backups ", $row->{'host'}, ":", $row->{'share'}, " #", $row->{'num'}, " -> $tar_file"; |
print curr_time, " $curr_backup/$num_backups ", $row->{'host'}, ":", $row->{'share'}, " #", $row->{'num'}, " -> $tar_file"; |
225 |
my $t = time(); |
my $t = time(); |
226 |
|
|
227 |
# re-create archive? |
# re-create archive? |
228 |
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 }; |
229 |
print STDERR "## $cmd\n" if ($debug); |
print STDERR "## $cmd\n" if ($debug); |
230 |
|
|
231 |
if (system($cmd) != 0) { |
if (system($cmd) != 0) { |