--- trunk/bin/BackupPC_incPartsUpdate 2005/12/12 13:41:04 252 +++ trunk/bin/BackupPC_incPartsUpdate 2005/12/12 13:41:08 253 @@ -32,7 +32,7 @@ die "can't find $tarIncCreate: $!\n" unless (-x $tarIncCreate); my $bin; -foreach my $c (qw/gzip split/) { +foreach my $c (qw/gzip/) { $bin->{$c} = which($c) || die "$0 needs $c, install it\n"; } @@ -72,20 +72,11 @@ return strftime($t_fmt,localtime()); } -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: $?"; - -} - sub tar_check($$$$) { my ($host,$share,$num,$filename) = @_; + return 1; # FIXME + if ($debug) { print STDERR " {{ CHECK: ${host}:${share}#${num} and $filename"; } else { @@ -174,10 +165,6 @@ } ); -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 = ? }); - - $sth->execute(); my $num_backups = $sth->rows; my $curr_backup = 1; @@ -188,74 +175,25 @@ # this will return -1 if file doesn't exist my $size = BackupPC::SearchLib::get_tgz_size_by_name($tar_file); + 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) ) { + next; + } + print curr_time, " $curr_backup/$num_backups ", $row->{'host'}, ":", $row->{'share'}, " #", $row->{'num'}, " -> $tar_file"; $curr_backup++; my $t = time(); # re-create archive? - if ($row->{'inc_size'} == -1 || $size == -1 || - $row->{'inc_size'} != $size || - $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: $?"; + my $cmd = qq{ $tarIncCreate -h "$row->{'host'}" -s "$row->{'share'}" -n $row->{'num'} }; + print STDERR "## $cmd\n" if ($debug); - rename("${tar_dir}/${tar_file}.tmp", "$tar_dir/$tar_file") or die "can't rename $tar_dir/$tar_file: $!"; - - $size = (stat( "$tar_dir/$tar_file" ))[7]; + if (system($cmd) != 0) { + print STDERR " FAILED"; } - 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"; - } print ", dur: ",fmt_time(time() - $t), "\n"; $dbh->commit;