/[BackupPC]/trunk/bin/BackupPC_incPartsUpdate
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/bin/BackupPC_incPartsUpdate

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 280 by dpavlin, Wed Dec 14 10:40:10 2005 UTC revision 281 by dpavlin, Wed Dec 14 14:57:51 2005 UTC
# Line 103  sub tar_check($$$$) { Line 103  sub tar_check($$$$) {
103          my $t = time();          my $t = time();
104          print curr_time, " check $host:$share#$num -> $filename";          print curr_time, " check $host:$share#$num -> $filename";
105    
106            # depending on expected returned value this is used like:
107            # my $uncompress_size = get_gzip_size('/full/path/to.gz');
108            # my ($compress_size, $uncompress_size) = get_gzip_size('/path.gz');
109            sub get_gzip_size($) {
110                    my $filename = shift;
111                    die "file $filename problem: $!" unless (-r $filename);
112                    open(my $gzip, $bin->{gzip}." -l $filename |") || die "can't gzip -l $filename: $!";
113                    my $line = <$gzip>;
114                    chomp($line);
115                    $line = <$gzip> if ($line =~ /^\s+compressed/);
116    
117                    my ($comp, $uncomp) = (0,0);
118    
119                    if ($line =~ m/^\s+(\d+)\s+(\d+)\s+\d+\.\d+/) {
120                            if (wantarray) {
121                                    return [ $1, $2 ];
122                            } else {
123                                    return $2;
124                            }
125                    } else {
126                            die "can't find size in line: $line";
127                    }
128            }
129    
130          sub check_part {          sub check_part {
131                  my ($host, $share, $num, $part_nr, $tar_size, $size, $md5, $items) = @_;                  my ($host, $share, $num, $part_nr, $tar_size, $size, $md5, $items) = @_;
132                  my $backup_id = get_backup_id($host, $share, $num);                  my $backup_id = get_backup_id($host, $share, $num);
# Line 165  sub tar_check($$$$) { Line 189  sub tar_check($$$$) {
189    
190                  print "\n\t- $tarfilename";                  print "\n\t- $tarfilename";
191    
192                  my $size = (stat( "$tar_dir/$tarfilename" ))[7] || die "can't stat $tar_dir/$tarfilename";                  my $path = "$tar_dir/$tarfilename";
193    
194                    my $size = (stat( $path ))[7] || die "can't stat $path: $!";
195    
196                  if ($size > $Conf{MaxArchiveSize}) {                  if ($size > $Conf{MaxArchiveSize}) {
197                          print ", part bigger than media $size > $Conf{MaxArchiveSize}\n";                          print ", part bigger than media $size > $Conf{MaxArchiveSize}\n";
# Line 174  sub tar_check($$$$) { Line 200  sub tar_check($$$$) {
200    
201                  print ", $size bytes";                  print ", $size bytes";
202    
                 my $path = "$tar_dir/$tarfilename";  
203    
204                  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: $!";
205                  binmode($fh);                  binmode($fh);
206                  my $tar = Archive::Tar::Streamed->new($fh);                  my $tar = Archive::Tar::Streamed->new($fh);
207    
208                  my $tar_size = 0;                  my $tar_size_inarc = 0;
209                  my $items = 0;                  my $items = 0;
210    
211                  while(my $entry = $tar->next) {                  while(my $entry = $tar->next) {
212                          push @tar_files, $entry->name;                          push @tar_files, $entry->name;
213                          $items++;                          $items++;
214                          $tar_size += $entry->size;                          $tar_size_inarc += $entry->size;
215    
216                          if ($tar_size > $Conf{MaxArchiveFileSize}) {                          if ($tar_size_inarc > $Conf{MaxArchiveFileSize}) {
217                                  print ", part $tarfilename is too big $tar_size > $Conf{MaxArchiveFileSize}\n";                                  print ", part $tarfilename is too big $tar_size_inarc > $Conf{MaxArchiveFileSize}\n";
218                                  return 0;                                  return 0;
219                          }                          }
220    
221                  }                  }
222    
223                    close($fh);
224    
225                  print ", $items items";                  print ", $items items";
226    
227                  if ($tar_size == 0 && $items == 0) {                  if ($tar_size_inarc == 0 && $items == 0) {
228                          print ", EMPTY tar\n";                          print ", EMPTY tar\n";
229    
230                          my $backup_id = get_backup_id($host, $share, $num);                          my $backup_id = get_backup_id($host, $share, $num);
# Line 214  sub tar_check($$$$) { Line 241  sub tar_check($$$$) {
241                          return 1;                          return 1;
242                  }                  }
243    
244                  # fix tar_size for tars without any files                  my $tar_size = get_gzip_size( $path );
                 $tar_size ||= 512 * $items;  
245    
246                    # real tar size is bigger because of padding    
247                    if ($tar_size_inarc > $tar_size) {
248                            print ", size of files in tar bigger than whole tar!\n";
249                            return 0;
250                    }
251    
252                  #                  #
253                  # check if md5 exists, and if not, create one                  # check if md5 exists, and if not, create one

Legend:
Removed from v.280  
changed lines
  Added in v.281

  ViewVC Help
Powered by ViewVC 1.1.26