/[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 289 by dpavlin, Wed Jan 18 15:16:31 2006 UTC revision 323 by dpavlin, Tue Jan 31 11:11:37 2006 UTC
# Line 18  use Getopt::Std; Line 18  use Getopt::Std;
18  use File::Slurp;  use File::Slurp;
19  use File::Pid;  use File::Pid;
20    
21    =head1 NAME
22    
23    BackupPC_incPartsUpdate
24    
25    =head1 DESCRIPTION
26    
27    Create C<.tar.gz> increments on disk calling C<BackupPC_tarIncCreate>.
28    
29    Following options are supported (but all are optional):
30    
31    =over 4
32    
33    =item -h hostname
34    
35    Update parts for just single C<hostname>
36    
37    =item -c
38    
39    Force check for tar archives which exist on disk
40    
41    =item -d
42    
43    Turn debugging output
44    
45    =back
46    
47    =cut
48    
49    my %opt;
50    getopts("cdh:", \%opt );
51    
52    my $debug = $opt{d};
53    my $check = $opt{c} && print STDERR "NOTICE: tar archive check forced\n";
54    
55  my $pid_path = abs_path($0);  my $pid_path = abs_path($0);
56  $pid_path =~ s/\W+/_/g;  $pid_path =~ s/\W+/_/g;
57    
# Line 52  foreach my $c (qw/gzip md5sum/) { Line 86  foreach my $c (qw/gzip md5sum/) {
86          $bin->{$c} = which($c) || die "$0 needs $c, install it\n";          $bin->{$c} = which($c) || die "$0 needs $c, install it\n";
87  }  }
88    
 my %opt;  
 getopts("cd", \%opt );  
   
 my $debug = $opt{d};  
 my $check = $opt{c} && print STDERR "NOTICE: tar archive check forced\n";  
   
89  $|=1;  $|=1;
90    
91  my $start_t = time();  my $start_t = time();
# Line 102  sub get_backup_id($$$) { Line 130  sub get_backup_id($$$) {
130                  FROM backups                  FROM backups
131                  INNER JOIN shares       ON backups.shareID=shares.ID                  INNER JOIN shares       ON backups.shareID=shares.ID
132                  INNER JOIN hosts        ON backups.hostID = hosts.ID                  INNER JOIN hosts        ON backups.hostID = hosts.ID
133                  where hosts.name = ? and shares.name = ? and backups.num = ?                  WHERE hosts.name = ? and shares.name = ? and backups.num = ?
134          });          });
135          $sth->execute($host, $share, $num);          $sth->execute($host, $share, $num);
136          my ($id) = $sth->fetchrow_array;          my ($id) = $sth->fetchrow_array;
# Line 114  sub get_backup_id($$$) { Line 142  sub get_backup_id($$$) {
142          return $id;          return $id;
143  }  }
144    
145    sub backup_inc_deleted($) {
146            my $backup_id = shift;
147            my $sth_inc_deleted = $dbh->prepare(qq{
148                    update backups set
149                            inc_deleted = true,
150                            parts = 0
151                    where id = ?
152            });
153            $sth_inc_deleted->execute($backup_id);
154    }
155    
156  sub tar_check($$$$) {  sub tar_check($$$$) {
157          my ($host,$share,$num,$filename) = @_;          my ($host,$share,$num,$filename) = @_;
# Line 246  sub tar_check($$$$) { Line 284  sub tar_check($$$$) {
284                          print ", EMPTY tar\n";                          print ", EMPTY tar\n";
285    
286                          my $backup_id = get_backup_id($host, $share, $num);                          my $backup_id = get_backup_id($host, $share, $num);
287                            backup_inc_deleted( $backup_id );
                         my $sth_inc_deleted = $dbh->prepare(qq{  
                                 update backups set  
                                         inc_deleted = true  
                                 where id = ?  
                         });  
                         $sth_inc_deleted->execute($backup_id);  
288    
289                          $dbh->commit;                          $dbh->commit;
290    
# Line 350  select Line 382  select
382          hosts.name as host,          hosts.name as host,
383          shares.name as share,          shares.name as share,
384          backups.num as num,          backups.num as num,
385            backups.date,
386          inc_size,          inc_size,
387          parts          parts,
388            count(backup_parts.backup_id) as backup_parts
389  from backups  from backups
390          join shares on backups.hostid = shares.hostid          join shares on backups.hostid = shares.hostid
391                  and shares.id = backups.shareid                  and shares.id = backups.shareid
392          join hosts on shares.hostid = hosts.id          join hosts on shares.hostid = hosts.id
393  where not inc_deleted          full outer join backup_parts on backups.id = backup_parts.backup_id
394    where not inc_deleted and backups.size > 0
395    group by backups.id, hosts.name, shares.name, backups.num, backups.date, inc_size, parts, backup_parts.backup_id
396  order by backups.date  order by backups.date
397    
398  } );  } );
# Line 365  $sth->execute(); Line 401  $sth->execute();
401  my $num_backups = $sth->rows;  my $num_backups = $sth->rows;
402  my $curr_backup = 1;  my $curr_backup = 1;
403    
404    if ($opt{h}) {
405            warn "making increments just for host $opt{h}\n";
406    }
407    
408  while (my $row = $sth->fetchrow_hashref) {  while (my $row = $sth->fetchrow_hashref) {
409    
410            if ($opt{h} && $row->{host} ne $opt{h}) {
411                    warn "skipped $row->{host}\n" if ($debug);
412                    next;
413            }
414    
415          $curr_backup++;          $curr_backup++;
416    
417          my $tar_file = BackupPC::SearchLib::getGzipName($row->{'host'}, $row->{'share'}, $row->{'num'});          my $tar_file = BackupPC::SearchLib::getGzipName($row->{'host'}, $row->{'share'}, $row->{'num'});
# Line 376  while (my $row = $sth->fetchrow_hashref) Line 421  while (my $row = $sth->fetchrow_hashref)
421    
422          print "# size: $size backup.size: ", $row->{inc_size},"\n" if ($opt{d});          print "# size: $size backup.size: ", $row->{inc_size},"\n" if ($opt{d});
423    
424          if ( $row->{'inc_size'} != -1 && $size != -1 && $row->{'inc_size'} >= $size) {          if ( $row->{'inc_size'} != -1 && $size != -1 && $row->{'inc_size'} >= $size && $row->{parts} == $row->{backup_parts}) {
425                  if ($check) {                  if ($check) {
426                          tar_check($row->{'host'}, $row->{'share'}, $row->{'num'}, $tar_file) && next;                          tar_check($row->{'host'}, $row->{'share'}, $row->{'num'}, $tar_file) && next;
427                  } else {                  } else {
# Line 384  while (my $row = $sth->fetchrow_hashref) Line 429  while (my $row = $sth->fetchrow_hashref)
429                  }                  }
430          }          }
431    
432          print curr_time, " creating $curr_backup/$num_backups ", $row->{'host'}, ":", $row->{'share'}, " #", $row->{'num'}, " -> $tar_file";          print curr_time, " creating $curr_backup/$num_backups ", $row->{host}, ":", $row->{share}, " #", $row->{num},
433                    " ", strftime('%Y-%m-%d', localtime($row->{date})), " -> $tar_file";
434    
435          my $t = time();          my $t = time();
436    
437          # re-create archive?          # re-create archive?
438          my $cmd = qq{ $tarIncCreate -h "$row->{'host'}" -s "$row->{'share'}" -n $row->{'num'} -f };          my $cmd = qq[ $tarIncCreate -h "$row->{host}" -s "$row->{share}" -n $row->{num} -f ];
439          print STDERR "## $cmd\n" if ($debug);          print STDERR "## $cmd\n" if ($debug);
440    
441          if (system($cmd) != 0) {          if (system($cmd) != 0) {
442                  print STDERR " FAILED";                  print STDERR " FAILED, marking this backup deleted";
443                    backup_inc_deleted( $row->{backup_id} );
444          }          }
445    
446          print ", dur: ",fmt_time(time() - $t), "\n";          print ", dur: ",fmt_time(time() - $t), "\n";

Legend:
Removed from v.289  
changed lines
  Added in v.323

  ViewVC Help
Powered by ViewVC 1.1.26