/[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 269 by dpavlin, Tue Dec 13 18:08:48 2005 UTC revision 270 by dpavlin, Tue Dec 13 18:08:50 2005 UTC
# Line 100  sub get_backup_id($$$) { Line 100  sub get_backup_id($$$) {
100  sub tar_check($$$$) {  sub tar_check($$$$) {
101          my ($host,$share,$num,$filename) = @_;          my ($host,$share,$num,$filename) = @_;
102    
103            my $t = time();
104            print curr_time, " check $host:$share#$num -> $filename";
105    
106          sub check_part {          sub check_part {
107                  my ($host, $share, $num, $part_nr, $tar_size, $size, $md5, $items) = @_;                  my ($host, $share, $num, $part_nr, $tar_size, $size, $md5, $items) = @_;
108                  my $backup_id = get_backup_id($host, $share, $num);                  my $backup_id = get_backup_id($host, $share, $num);
# Line 119  sub tar_check($$$$) { Line 122  sub tar_check($$$$) {
122                                  $row->{md5} eq $md5 &&                                  $row->{md5} eq $md5 &&
123                                  $row->{items} == $items                                  $row->{items} == $items
124                          );                          );
125                          print STDERR "# deleting invalid row $row->{id}\n" if ($opt{d});                          print ", deleting invalid backup_parts $row->{id}";
126                          $dbh->do(qq{ delete from backup_parts where id = $row->{id} });                          $dbh->do(qq{ delete from backup_parts where id = $row->{id} });
127                  }                  }
128                  print STDERR "# inserting new backup_part row\n";                  print ", inserting new";
129                  my $sth_insert = $dbh->prepare(qq{                  my $sth_insert = $dbh->prepare(qq{
130                          insert into backup_parts (                          insert into backup_parts (
131                                  backup_id,                                  backup_id,
# Line 138  sub tar_check($$$$) { Line 141  sub tar_check($$$$) {
141                  $dbh->commit;                  $dbh->commit;
142          }          }
143    
         if ($debug) {  
                 print STDERR " {{ CHECK: ${host}:${share}#${num} and $filename";  
         } else {  
                 print " check $filename";  
         }  
   
144          my @tar_parts;          my @tar_parts;
145    
146          if (-d "$tar_dir/$filename") {          if (-d "$tar_dir/$filename") {
147                  print STDERR " multi-part" if ($opt{d});                  print ", multi-part";
148                  opendir(my $dir, "$tar_dir/$filename") || die "can't readdir $tar_dir/$filename: $!";                  opendir(my $dir, "$tar_dir/$filename") || die "can't readdir $tar_dir/$filename: $!";
149                  @tar_parts = map { my $p = $_; $p =~ s#^#${filename}/#; $p } grep { !/^\./ && !/md5/ && -f "$tar_dir/$filename/$_" } readdir($dir);                  @tar_parts = map { my $p = $_; $p =~ s#^#${filename}/#; $p } grep { !/^\./ && !/md5/ && -f "$tar_dir/$filename/$_" } readdir($dir);
150                  closedir($dir);                  closedir($dir);
# Line 166  sub tar_check($$$$) { Line 163  sub tar_check($$$$) {
163    
164          foreach my $tarfilename (@tar_parts) {          foreach my $tarfilename (@tar_parts) {
165    
166                  print STDERR " $tarfilename" if ($debug);                  print "\n\t- $tarfilename";
167    
168                  my $size = (stat( "$tar_dir/$tarfilename" ))[7] || die "can't stat $tar_dir/$tarfilename";                  my $size = (stat( "$tar_dir/$tarfilename" ))[7] || die "can't stat $tar_dir/$tarfilename";
169    
# Line 176  sub tar_check($$$$) { Line 173  sub tar_check($$$$) {
173                          last;                          last;
174                  }                  }
175    
176                    print ", $size bytes";
177    
178                  my $path = "$tar_dir/$tarfilename";                  my $path = "$tar_dir/$tarfilename";
179    
180                  open(my $fh, "gzip -cd $tar_dir/$tarfilename |") or die "can't open $tar_dir/$tarfilename: $!";                  open(my $fh, "gzip -cd $tar_dir/$tarfilename |") or die "can't open $tar_dir/$tarfilename: $!";
# Line 191  sub tar_check($$$$) { Line 190  sub tar_check($$$$) {
190                          $tar_size += $entry->size;                          $tar_size += $entry->size;
191    
192                          if ($tar_size > $Conf{MaxArchiveFileSize}) {                          if ($tar_size > $Conf{MaxArchiveFileSize}) {
193                                  print STDERR " part too big $tar_size > $Conf{MaxArchiveFileSize} }}" if ($debug);                                  print ", part $tarfilename is too big $tar_size > $Conf{MaxArchiveFileSize}\n";
194                                  $same = 0;                                  $same = 0;
195                                  last;                                  last;
196                          }                          }
197    
198                  }                  }
199    
200                    print ", $items items";
201    
202                  #                  #
203                  # check if md5 exists, and if not, create one                  # check if md5 exists, and if not, create one
204                  #                  #
# Line 207  sub tar_check($$$$) { Line 208  sub tar_check($$$$) {
208                  if (! -e $md5_path || -z $md5_path) {                  if (! -e $md5_path || -z $md5_path) {
209                          print ", creating md5";                          print ", creating md5";
210                          system( $bin->{md5sum} . " $path > $md5_path") == 0 or die "can't create md5 $path: $!";                          system( $bin->{md5sum} . " $path > $md5_path") == 0 or die "can't create md5 $path: $!";
211                    } else {
212                            ## FIXME check if existing md5 is valid
213                  }                  }
214    
215                  my $md5 = read_file( $md5_path ) || die "can't read md5sum file $md5_path: $!";                  my $md5 = read_file( $md5_path ) || die "can't read md5sum file $md5_path: $!";
# Line 227  sub tar_check($$$$) { Line 230  sub tar_check($$$$) {
230          return $same unless($same);          return $same unless($same);
231    
232          @tar_files = sort @tar_files;          @tar_files = sort @tar_files;
233          print STDERR " ",($#tar_files + 1), " files" if ($debug);          print "\n\t",($#tar_files + 1), " tar files";
   
         print STDERR ", database" if ($debug);  
234    
235          my $sth = $dbh->prepare(qq{          my $sth = $dbh->prepare(qq{
236                  SELECT path,type                  SELECT path,type
# Line 248  sub tar_check($$$$) { Line 249  sub tar_check($$$$) {
249                  push @db_files, $path;                  push @db_files, $path;
250          }          }
251    
252          print STDERR " ",($#db_files + 1), " files, diff" if ($debug);          print " ",($#db_files + 1), " database files, diff";
253    
254          @db_files = sort @db_files;          @db_files = sort @db_files;
255    
256          if ($#tar_files != $#db_files) {          if ($#tar_files != $#db_files) {
257                  $same = 0;                  $same = 0;
258                  print STDERR " NUMBER" if ($debug);                  print " NUMBER";
259          } else {          } else {
260                  my $diff = Algorithm::Diff->new(\@tar_files, \@db_files);                  my $diff = Algorithm::Diff->new(\@tar_files, \@db_files);
261                  while ( $diff->Next() ) {                  while ( $diff->Next() ) {
# Line 265  sub tar_check($$$$) { Line 266  sub tar_check($$$$) {
266                  }                  }
267          }          }
268    
269          print " ",($same ? 'ok' : 'DIFFERENT');          print " ",($same ? 'ok' : 'DIFFERENT'),
270          print STDERR " }} " if ($debug);                  ", dur: ",fmt_time(time() - $t), "\n";
271    
272          return $same;          return $same;
273  }  }

Legend:
Removed from v.269  
changed lines
  Added in v.270

  ViewVC Help
Powered by ViewVC 1.1.26