/[BackupPC]/trunk/bin/BackupPC_updatedb
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_updatedb

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

revision 35 by dpavlin, Sun Jul 31 21:03:36 2005 UTC revision 40 by dpavlin, Fri Aug 19 15:38:56 2005 UTC
# Line 7  use BackupPC::Lib; Line 7  use BackupPC::Lib;
7  use BackupPC::View;  use BackupPC::View;
8  use Data::Dumper;  use Data::Dumper;
9  use Getopt::Std;  use Getopt::Std;
10    use Time::HiRes qw/time/;
11    use File::Pid;
12    use POSIX qw/strftime/;
13  use constant BPC_FTYPE_DIR => 5;  use constant BPC_FTYPE_DIR => 5;
14    
15  my $debug = 0;  my $debug = 0;
16  $|=1;  $|=1;
17    
18    my $pidfile = new File::Pid;
19    
20    if (my $pid = $pidfile->running ) {
21            die "$0 already running: $pid\n";
22    } elsif ($pidfile->pid ne $$) {
23            $pidfile->remove;
24            $pidfile = new File::Pid;
25    }
26    $pidfile->write;
27    print STDERR "$0 using pid ",$pidfile->pid," file ",$pidfile->file,"\n";
28    
29    my $t_fmt = '%Y-%m-%d %H:%M:%S';
30    
31  my $hosts;  my $hosts;
32  my $bpc = BackupPC::Lib->new || die;  my $bpc = BackupPC::Lib->new || die;
33  my %Conf = $bpc->Conf();  my %Conf = $bpc->Conf();
# Line 186  foreach my $host_key (keys %{$hosts}) { Line 202  foreach my $host_key (keys %{$hosts}) {
202          my $inc_nr = 0;          my $inc_nr = 0;
203    
204          foreach my $backup (@backups) {          foreach my $backup (@backups) {
205    
206                  $inc_nr++;                  $inc_nr++;
207                  last if ($opt{m} && $inc_nr > $opt{m});                  last if ($opt{m} && $inc_nr > $opt{m});
208    
209                  my $backupNum = $backup->{'num'};                  my $backupNum = $backup->{'num'};
210                  my @backupShares = ();                  my @backupShares = ();
211    
212                  print $hosts->{$host_key}->{'host'},"\t#$backupNum\n";                  print $hosts->{$host_key}->{'host'},
213                            "\t#$backupNum\t",
214                            $backup->{nFilesNew} || '?', "/", $backup->{nFiles} || '?',
215                            " files\n";
216    
217                  $sth->{backups_broj}->execute($hostID, $backupNum);                  $sth->{backups_broj}->execute($hostID, $backupNum);
218                  my ($broj) = $sth->{backups_broj}->fetchrow_array();                  my ($broj) = $sth->{backups_broj}->fetchrow_array();
# Line 201  foreach my $host_key (keys %{$hosts}) { Line 221  foreach my $host_key (keys %{$hosts}) {
221                  my $files = BackupPC::View->new($bpc, $hostname, \@backups, 1);                  my $files = BackupPC::View->new($bpc, $hostname, \@backups, 1);
222                  foreach my $share ($files->shareList($backupNum)) {                  foreach my $share ($files->shareList($backupNum)) {
223    
224                          print "\t$share";                          my $t = time();
225    
226                            print strftime($t_fmt,localtime())," ", $share;
227                          $shareID = getShareID($share, $hostID, $hostname);                          $shareID = getShareID($share, $hostID, $hostname);
228                                    
229                          my ($f, $nf, $d, $nd) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID);                          my ($f, $nf, $d, $nd) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID);
230                          print " $nf/$f files $nd/$d dirs\n";                          printf(" %d/%d files %d/%d dirs [%.2f/s]\n",
231                                    $nf, $f, $nd, $d,
232                                    ( ($f+$d) / ((time() - $t) || 1) )
233                            );
234                          $dbh->commit();                          $dbh->commit();
235                  }                  }
236    
# Line 223  undef $sth; Line 248  undef $sth;
248  $dbh->commit();  $dbh->commit();
249  $dbh->disconnect();  $dbh->disconnect();
250    
251    $pidfile->remove;
252    
253  sub getShareID() {  sub getShareID() {
254    
255          my ($share, $hostID, $hostname) = @_;          my ($share, $hostID, $hostname) = @_;

Legend:
Removed from v.35  
changed lines
  Added in v.40

  ViewVC Help
Powered by ViewVC 1.1.26