32 |
die "can't find $tarIncCreate: $!\n" unless (-x $tarIncCreate); |
die "can't find $tarIncCreate: $!\n" unless (-x $tarIncCreate); |
33 |
|
|
34 |
my $bin; |
my $bin; |
35 |
foreach my $c (qw/gzip split/) { |
foreach my $c (qw/gzip/) { |
36 |
$bin->{$c} = which($c) || die "$0 needs $c, install it\n"; |
$bin->{$c} = which($c) || die "$0 needs $c, install it\n"; |
37 |
} |
} |
38 |
|
|
72 |
return strftime($t_fmt,localtime()); |
return strftime($t_fmt,localtime()); |
73 |
} |
} |
74 |
|
|
|
sub tar_join($) { |
|
|
my $filename = shift; |
|
|
|
|
|
my $in = my $out = $filename; |
|
|
$out .= '.tmp'; |
|
|
|
|
|
# FIXME I should really order parts manually! |
|
|
system("cat $in/part* > $out && rm -Rf $in && mv $out $in") == 0 or die "can't join $in: $?"; |
|
|
|
|
|
} |
|
|
|
|
75 |
sub tar_check($$$$) { |
sub tar_check($$$$) { |
76 |
my ($host,$share,$num,$filename) = @_; |
my ($host,$share,$num,$filename) = @_; |
77 |
|
|
78 |
|
return 1; # FIXME |
79 |
|
|
80 |
if ($debug) { |
if ($debug) { |
81 |
print STDERR " {{ CHECK: ${host}:${share}#${num} and $filename"; |
print STDERR " {{ CHECK: ${host}:${share}#${num} and $filename"; |
82 |
} else { |
} else { |
165 |
|
|
166 |
} ); |
} ); |
167 |
|
|
|
my $sth_inc_size = $dbh->prepare(qq{ update backups set inc_size = ?, parts = ? where id = ? }); |
|
|
my $sth_inc_deleted = $dbh->prepare(qq{ update backups set inc_deleted = ? where id = ? }); |
|
|
|
|
|
|
|
168 |
$sth->execute(); |
$sth->execute(); |
169 |
my $num_backups = $sth->rows; |
my $num_backups = $sth->rows; |
170 |
my $curr_backup = 1; |
my $curr_backup = 1; |
175 |
# this will return -1 if file doesn't exist |
# this will return -1 if file doesn't exist |
176 |
my $size = BackupPC::SearchLib::get_tgz_size_by_name($tar_file); |
my $size = BackupPC::SearchLib::get_tgz_size_by_name($tar_file); |
177 |
|
|
178 |
|
print "# size: $size backup.size: ", $row->{inc_size},"\n" if ($opt{d}); |
179 |
|
|
180 |
|
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) ) { |
181 |
|
next; |
182 |
|
} |
183 |
|
|
184 |
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"; |
185 |
$curr_backup++; |
$curr_backup++; |
186 |
|
|
187 |
my $t = time(); |
my $t = time(); |
188 |
|
|
189 |
# re-create archive? |
# re-create archive? |
190 |
if ($row->{'inc_size'} == -1 || $size == -1 || |
my $cmd = qq{ $tarIncCreate -h "$row->{'host'}" -s "$row->{'share'}" -n $row->{'num'} }; |
191 |
$row->{'inc_size'} != $size || |
print STDERR "## $cmd\n" if ($debug); |
|
$check && ! tar_check($row->{'host'}, $row->{'share'}, $row->{'num'}, "$tar_dir/$tar_file") |
|
|
) { |
|
|
my $cmd = qq{rm -Rf $tar_dir/$tar_file && $tarIncCreate -h "$row->{'host'}" -s "$row->{'share'}" -n $row->{'num'} | $bin->{'gzip'} $Conf{GzipLevel} > ${tar_dir}/${tar_file}.tmp}; |
|
|
print STDERR "## $cmd\n" if ($debug); |
|
|
|
|
|
system($cmd) == 0 or die "failed: $?"; |
|
192 |
|
|
193 |
rename("${tar_dir}/${tar_file}.tmp", "$tar_dir/$tar_file") or die "can't rename $tar_dir/$tar_file: $!"; |
if (system($cmd) != 0) { |
194 |
|
print STDERR " FAILED"; |
|
$size = (stat( "$tar_dir/$tar_file" ))[7]; |
|
195 |
} |
} |
196 |
|
|
|
if ($size > $MIN_TAR_SIZE) { |
|
|
|
|
|
my $max_size = $Conf{'MaxArchiveSize'} || die "problem with MaxArchiveSize parametar"; |
|
|
$max_size *= 1024; # convert to bytes |
|
|
|
|
|
my $max_file_size = $Conf{'MaxArchiveFileSize'} || die "problem with MaxArchiveFileSize parametar"; |
|
|
$max_file_size *= 1024; # bytes |
|
|
|
|
|
if ($max_file_size > $max_size) { |
|
|
warn "MaxArchiveFileSize ($max_file_size) is bigger than MaxArchiveSize ($max_size)\n"; |
|
|
$max_file_size = $max_size; |
|
|
} |
|
|
|
|
|
# maximum file size on ISO image is 4Gb |
|
|
# this will require Linux kernel 2.6.8 or newer |
|
|
if ( $max_size > $max_file_size ) { |
|
|
$max_size = $max_file_size; |
|
|
} |
|
|
|
|
|
my $parts = int( ($size + $max_size - 1) / $max_size ); |
|
|
|
|
|
if (-d "$tar_dir/$tar_file" && $parts != $row->{'parts'}) { |
|
|
print " join"; |
|
|
tar_join("$tar_dir/$tar_file"); |
|
|
} |
|
|
|
|
|
if ($size > $max_size && ! -d "$tar_dir/$tar_file") { |
|
|
print " split/$parts"; |
|
|
my $in = my $out = "$tar_dir/$tar_file"; |
|
|
$out .= '.tmp'; |
|
|
rename $in, $out || die "can't rename $in: $!"; |
|
|
mkdir $in || die "can't mkdir $in: $!"; |
|
|
|
|
|
my $suffix_len = length("$parts"); |
|
|
system("$bin->{'split'} -d -b $max_size -a $suffix_len $out $in/part") == 0 or die "can't split $out: $?"; |
|
|
unlink $out || die "can't unlink $out: $!"; |
|
|
} |
|
|
|
|
|
$sth_inc_size->execute($size, $parts, $row->{'backup_id'}); |
|
|
$sth_inc_deleted->execute(0, $row->{'backup_id'}); |
|
|
|
|
|
printf(" %1.2f MB", ($size / 1024 / 1024)); |
|
|
|
|
|
} else { |
|
|
$sth_inc_deleted->execute(1, $row->{'backup_id'}); |
|
|
unlink "$tar_dir/$tar_file" || die "can't delete $tar_dir/$tar_file: $!\n"; |
|
|
print " EMPTY"; |
|
|
} |
|
197 |
print ", dur: ",fmt_time(time() - $t), "\n"; |
print ", dur: ",fmt_time(time() - $t), "\n"; |
198 |
|
|
199 |
$dbh->commit; |
$dbh->commit; |