16 |
use Algorithm::Diff; |
use Algorithm::Diff; |
17 |
use Getopt::Std; |
use Getopt::Std; |
18 |
use File::Slurp; |
use File::Slurp; |
19 |
|
use File::Pid; |
20 |
|
|
21 |
|
my $pid_path = abs_path($0); |
22 |
|
$pid_path =~ s/\W+/_/g; |
23 |
|
|
24 |
|
my $pidfile = new File::Pid({ |
25 |
|
file => "/tmp/$pid_path", |
26 |
|
}); |
27 |
|
|
28 |
|
if (my $pid = $pidfile->running ) { |
29 |
|
die "$0 already running: $pid\n"; |
30 |
|
} elsif ($pidfile->pid ne $$) { |
31 |
|
$pidfile->remove; |
32 |
|
$pidfile = new File::Pid; |
33 |
|
} |
34 |
|
|
35 |
|
print STDERR "$0 using pid ",$pidfile->pid," file ",$pidfile->file,"\n"; |
36 |
|
$pidfile->write; |
37 |
|
|
38 |
my $bpc = BackupPC::Lib->new || die "can't create BackupPC::Lib"; |
my $bpc = BackupPC::Lib->new || die "can't create BackupPC::Lib"; |
39 |
my %Conf = $bpc->Conf(); |
my %Conf = $bpc->Conf(); |
121 |
my $t = time(); |
my $t = time(); |
122 |
print curr_time, " check $host:$share#$num -> $filename"; |
print curr_time, " check $host:$share#$num -> $filename"; |
123 |
|
|
124 |
|
# depending on expected returned value this is used like: |
125 |
|
# my $uncompress_size = get_gzip_size('/full/path/to.gz'); |
126 |
|
# my ($compress_size, $uncompress_size) = get_gzip_size('/path.gz'); |
127 |
|
sub get_gzip_size($) { |
128 |
|
my $filename = shift; |
129 |
|
die "file $filename problem: $!" unless (-r $filename); |
130 |
|
open(my $gzip, $bin->{gzip}." -l $filename |") || die "can't gzip -l $filename: $!"; |
131 |
|
my $line = <$gzip>; |
132 |
|
chomp($line); |
133 |
|
$line = <$gzip> if ($line =~ /^\s+compressed/); |
134 |
|
|
135 |
|
my ($comp, $uncomp) = (0,0); |
136 |
|
|
137 |
|
if ($line =~ m/^\s+(\d+)\s+(\d+)\s+\d+\.\d+/) { |
138 |
|
if (wantarray) { |
139 |
|
return [ $1, $2 ]; |
140 |
|
} else { |
141 |
|
return $2; |
142 |
|
} |
143 |
|
} else { |
144 |
|
die "can't find size in line: $line"; |
145 |
|
} |
146 |
|
} |
147 |
|
|
148 |
sub check_part { |
sub check_part { |
149 |
my ($host, $share, $num, $part_nr, $tar_size, $size, $md5, $items) = @_; |
my ($host, $share, $num, $part_nr, $tar_size, $size, $md5, $items) = @_; |
150 |
my $backup_id = get_backup_id($host, $share, $num); |
my $backup_id = get_backup_id($host, $share, $num); |
207 |
|
|
208 |
print "\n\t- $tarfilename"; |
print "\n\t- $tarfilename"; |
209 |
|
|
210 |
my $size = (stat( "$tar_dir/$tarfilename" ))[7] || die "can't stat $tar_dir/$tarfilename"; |
my $path = "$tar_dir/$tarfilename"; |
211 |
|
|
212 |
|
my $size = (stat( $path ))[7] || die "can't stat $path: $!"; |
213 |
|
|
214 |
if ($size > $Conf{MaxArchiveSize}) { |
if ($size > $Conf{MaxArchiveSize}) { |
215 |
print STDERR " part bigger than media $size > $Conf{MaxArchiveSize} }}" if ($debug); |
print ", part bigger than media $size > $Conf{MaxArchiveSize}\n"; |
216 |
$same = 0; |
return 0; |
|
last; |
|
217 |
} |
} |
218 |
|
|
219 |
print ", $size bytes"; |
print ", $size bytes"; |
220 |
|
|
|
my $path = "$tar_dir/$tarfilename"; |
|
221 |
|
|
222 |
open(my $fh, "gzip -cd $tar_dir/$tarfilename |") or die "can't open $tar_dir/$tarfilename: $!"; |
open(my $fh, "gzip -cd $path |") or die "can't open $path: $!"; |
223 |
binmode($fh); |
binmode($fh); |
224 |
my $tar = Archive::Tar::Streamed->new($fh); |
my $tar = Archive::Tar::Streamed->new($fh); |
225 |
|
|
226 |
my $tar_size = 0; |
my $tar_size_inarc = 0; |
227 |
my $items = 0; |
my $items = 0; |
228 |
|
|
229 |
while(my $entry = $tar->next) { |
while(my $entry = $tar->next) { |
230 |
push @tar_files, $entry->name; |
push @tar_files, $entry->name; |
231 |
$items++; |
$items++; |
232 |
$tar_size += $entry->size; |
$tar_size_inarc += $entry->size; |
233 |
|
|
234 |
if ($tar_size > $Conf{MaxArchiveFileSize}) { |
if ($tar_size_inarc > $Conf{MaxArchiveFileSize}) { |
235 |
print ", part $tarfilename is too big $tar_size > $Conf{MaxArchiveFileSize}\n"; |
print ", part $tarfilename is too big $tar_size_inarc > $Conf{MaxArchiveFileSize}\n"; |
236 |
$same = 0; |
return 0; |
|
last; |
|
237 |
} |
} |
238 |
|
|
239 |
} |
} |
240 |
|
|
241 |
|
close($fh); |
242 |
|
|
243 |
print ", $items items"; |
print ", $items items"; |
244 |
|
|
245 |
|
if ($tar_size_inarc == 0 && $items == 0) { |
246 |
|
print ", EMPTY tar\n"; |
247 |
|
|
248 |
|
my $backup_id = get_backup_id($host, $share, $num); |
249 |
|
|
250 |
|
my $sth_inc_deleted = $dbh->prepare(qq{ |
251 |
|
update backups set |
252 |
|
inc_deleted = true |
253 |
|
where id = ? |
254 |
|
}); |
255 |
|
$sth_inc_deleted->execute($backup_id); |
256 |
|
|
257 |
|
$dbh->commit; |
258 |
|
|
259 |
|
return 1; |
260 |
|
} |
261 |
|
|
262 |
|
my $tar_size = get_gzip_size( $path ); |
263 |
|
|
264 |
|
# real tar size is bigger because of padding |
265 |
|
if ($tar_size_inarc > $tar_size) { |
266 |
|
print ", size of files in tar ($tar_size_inarc) bigger than whole tar ($tar_size)!\n"; |
267 |
|
return 0; |
268 |
|
} |
269 |
|
|
270 |
# |
# |
271 |
# check if md5 exists, and if not, create one |
# check if md5 exists, and if not, create one |
272 |
# |
# |