r11637@llin: dpavlin | 2005-12-12 15:40:59 +0100
authordpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Mon, 12 Dec 2005 13:41:08 +0000 (13:41 +0000)
committerdpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Mon, 12 Dec 2005 13:41:08 +0000 (13:41 +0000)
 create increments using new BackupPC_tarIncCreate

git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/BackupPC/trunk@253 8392b6e1-25fa-0310-8288-cc32f8e212ea

bin/BackupPC_incPartsUpdate
bin/BackupPC_tarIncCreate
lib/BackupPC/SearchLib.pm

index ab6b8ce..517acc2 100755 (executable)
@@ -32,7 +32,7 @@ my $tarIncCreate = $path .= 'BackupPC_tarIncCreate';
 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 @@ sub curr_time {
        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 @@ order by backups.date
 
 } );
 
-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 @@ while (my $row = $sth->fetchrow_hashref) {
        # 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;
index 9354b86..f9ac5cb 100755 (executable)
@@ -272,7 +272,8 @@ sub new_tar_part {
                        $items_in_part,
                );
 
-               $total_increment_size += int( ( $size + 1023 ) / 1024 ) * 1024;
+               #$total_increment_size += int( ( $size + 1023 ) / 1024 ) * 1024;
+               $total_increment_size += $size;
 
                if ($arg->{close}) {
 
@@ -310,7 +311,7 @@ sub new_tar_part {
        # if this is first part, create directory
 
        if ($part == 1) {
-               if (-d $tar_path) {
+               if (-e $tar_path) {
                        print STDERR "# deleting existing $tar_path\n" if ($opts{d});
                        rmtree($tar_path);
                }
index 7d617a1..8aa0e12 100644 (file)
@@ -377,8 +377,8 @@ sub get_tgz_size_by_name($) {
 
        my $size = -1;
 
-       if (-f $tgz) {
-               $size = (stat($tgz))[7];
+       if (-f "${tgz}.tar.gz") {
+               $size = (stat("${tgz}.tar.gz"))[7];
        } elsif (-d $tgz) {
                opendir(my $dir, $tgz) || die "can't opendir $tgz: $!";
                my @parts = grep { !/^\./ && -f "$tgz/$_" } readdir($dir);