/[BackupPC]/trunk/bin/BackupPC_tarIncCreate
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_tarIncCreate

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

revision 235 by dpavlin, Thu Nov 10 15:07:10 2005 UTC revision 236 by dpavlin, Thu Nov 10 15:38:14 2005 UTC
# Line 109  EOF Line 109  EOF
109  }  }
110    
111  if ( $opts{h} !~ /^([\w\.\s-]+)$/ ) {  if ( $opts{h} !~ /^([\w\.\s-]+)$/ ) {
112      print(STDERR "$0: bad host name '$opts{h}'\n");      die "$0: bad host name '$opts{h}'\n";
     exit(1);  
113  }  }
114  my $Host = $opts{h};  my $Host = $opts{h};
115    
116  if ( $opts{n} !~ /^(-?\d+)$/ ) {  if ( $opts{n} !~ /^(-?\d+)$/ ) {
117      print(STDERR "$0: bad dump number '$opts{n}'\n");      die "$0: bad dump number '$opts{n}'\n";
     exit(1);  
118  }  }
119  my $Num = $opts{n};  my $Num = $opts{n};
120    
# Line 132  my $DirCnt = 0; Line 130  my $DirCnt = 0;
130  my $SpecialCnt = 0;  my $SpecialCnt = 0;
131  my $ErrorCnt = 0;  my $ErrorCnt = 0;
132  my $current_tar_size = 0;  my $current_tar_size = 0;
133    my $total_increment_size = 0;
134    
135  my $i;  my $i;
136  $Num = $Backups[@Backups + $Num]{num} if ( -@Backups <= $Num && $Num < 0 );  $Num = $Backups[@Backups + $Num]{num} if ( -@Backups <= $Num && $Num < 0 );
# Line 139  for ( $i = 0 ; $i < @Backups ; $i++ ) { Line 138  for ( $i = 0 ; $i < @Backups ; $i++ ) {
138      last if ( $Backups[$i]{num} == $Num );      last if ( $Backups[$i]{num} == $Num );
139  }  }
140  if ( $i >= @Backups ) {  if ( $i >= @Backups ) {
141      print(STDERR "$0: bad backup number $Num for host $Host\n");      die "$0: bad backup number $Num for host $Host\n";
     exit(1);  
142  }  }
143    
144  my $PathRemove = $1 if ( $opts{r} =~ /(.+)/ );  my $PathRemove = $1 if ( $opts{r} =~ /(.+)/ );
145  my $PathAdd    = $1 if ( $opts{p} =~ /(.+)/ );  my $PathAdd    = $1 if ( $opts{p} =~ /(.+)/ );
146  if ( $opts{s} !~ /^([\w\s\.\/\$-]+)$/ && $opts{s} ne "*" ) {  if ( $opts{s} !~ /^([\w\s\.\/\$-]+)$/ && $opts{s} ne "*" ) {
147      print(STDERR "$0: bad share name '$opts{s}'\n");      die "$0: bad share name '$opts{s}'\n";
     exit(1);  
148  }  }
149  our $ShareName = $opts{s};  our $ShareName = $opts{s};
150  our $view = BackupPC::View->new($bpc, $Host, \@Backups);  our $view = BackupPC::View->new($bpc, $Host, \@Backups);
# Line 231  my $no_files = 0; Line 228  my $no_files = 0;
228  my $items_in_part = 0;  my $items_in_part = 0;
229    
230  sub new_tar_part {  sub new_tar_part {
231            my $arg = {@_};
232    
233          if ($fh) {          if ($fh) {
234                  return if ($current_tar_size == 0);                  return if ($current_tar_size == 0);
235    
236                  print STDERR "# closing part $part\n" if ($opts{d});                  print STDERR "# closing part $part\n" if ($opts{d});
237    
238                  # finish tar archive                  #
239                    # Finish with two null 512 byte headers,
240                    # and then round out a full block.
241                    #
242                  my $data = "\0" x ($tar_header_length * 2);                  my $data = "\0" x ($tar_header_length * 2);
243                  TarWrite($fh, \$data);                  TarWrite($fh, \$data);
244                  TarWrite($fh, undef);                  TarWrite($fh, undef);
# Line 259  sub new_tar_part { Line 261  sub new_tar_part {
261                          $items_in_part,                          $items_in_part,
262                  );                  );
263    
264                    $total_increment_size += int( ( $size + 1023 ) / 1024 ) * 1024;
265    
266                    if ($arg->{close}) {
267                            print STDERR "# close last part\n" if ($opts{d});
268                            $sth_inc_size->execute(
269                                    $total_increment_size,
270                                    $part,
271                                    $backup_id
272                            );
273                            return;
274                    }
275    
276          }          }
277    
278          $part++;          $part++;
# Line 271  sub new_tar_part { Line 285  sub new_tar_part {
285                          rmtree($tar_path);                          rmtree($tar_path);
286                  }                  }
287                  mkdir($tar_path) || die "can't create directory $tar_path: $!";                  mkdir($tar_path) || die "can't create directory $tar_path: $!";
288    
289                    sub abort_cleanup {
290                            print STDERR "ABORTED: cleanup temp dir";
291                            rmtree($tar_path);
292                            $dbh->rollback;
293                            exit 1;
294                    }
295    
296                    $SIG{'INT'}  = \&abort_cleanup;
297                    $SIG{'QUIT'} = \&abort_cleanup;
298                    $SIG{'__DIE__'} = \&abort_cleanup;
299    
300          }          }
301    
302          my $file = $tar_path . '/' . $part;          my $file = $tar_path . '/' . $part;
# Line 304  if (seedCache($Host, $ShareName, $Num)) Line 330  if (seedCache($Host, $ShareName, $Num))
330          $no_files = 1;          $no_files = 1;
331  }  }
332    
333  #  new_tar_part( close => 1 );
 # Finish with two null 512 byte headers, and then round out a full  
 # block.  
 #  
 my $data = "\0" x ($tar_header_length * 2);  
 TarWrite($fh, \$data);  
 TarWrite($fh, undef);  
   
 if (! close($fh)) {  
         rmtree($tar_path);  
         die "can't close archive\n";  
 }  
334    
335  # remove temporary files if there are no files  # remove temporary files if there are no files
336  if ($no_files) {  if ($no_files) {
# Line 336  if ( $ErrorCnt && !$FileCnt && !$DirCnt Line 351  if ( $ErrorCnt && !$FileCnt && !$DirCnt
351      # Got errors, with no files or directories; exit with non-zero      # Got errors, with no files or directories; exit with non-zero
352      # status      # status
353      #      #
354      cleanup();      die "got errors or no files\n";
     exit(1);  
355  }  }
356    
357  $sth_inc_size->finish;  $sth_inc_size->finish;
# Line 346  $sth_backup_parts->finish; Line 360  $sth_backup_parts->finish;
360  $dbh->commit || die "can't commit changes to database";  $dbh->commit || die "can't commit changes to database";
361  $dbh->disconnect();  $dbh->disconnect();
362    
363  exit(0);  exit;
364    
365  ###########################################################################  ###########################################################################
366  # Subroutines  # Subroutines
# Line 433  sub TarWrite Line 447  sub TarWrite
447      my $done = $WriteBufSz - length($WriteBuf);      my $done = $WriteBufSz - length($WriteBuf);
448      if ( syswrite($fh, $WriteBuf . substr($$dataRef, 0, $done))      if ( syswrite($fh, $WriteBuf . substr($$dataRef, 0, $done))
449                                  != $WriteBufSz ) {                                  != $WriteBufSz ) {
450          print(STDERR "Unable to write to output file ($!)\n");          die "Unable to write to output file ($!)\n";
         exit(1);  
451      }      }
452      while ( $done + $WriteBufSz <= length($$dataRef) ) {      while ( $done + $WriteBufSz <= length($$dataRef) ) {
453          if ( syswrite($fh, substr($$dataRef, $done, $WriteBufSz))          if ( syswrite($fh, substr($$dataRef, $done, $WriteBufSz))
454                              != $WriteBufSz ) {                              != $WriteBufSz ) {
455              print(STDERR "Unable to write to output file ($!)\n");              die "Unable to write to output file ($!)\n";
             exit(1);  
456          }          }
457          $done += $WriteBufSz;          $done += $WriteBufSz;
458      }      }

Legend:
Removed from v.235  
changed lines
  Added in v.236

  ViewVC Help
Powered by ViewVC 1.1.26