/[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 49 by dpavlin, Sat Aug 20 15:01:48 2005 UTC revision 57 by dpavlin, Sun Aug 21 14:25:46 2005 UTC
# Line 17  use constant BPC_FTYPE_DIR => 5; Line 17  use constant BPC_FTYPE_DIR => 5;
17  my $debug = 0;  my $debug = 0;
18  $|=1;  $|=1;
19    
20    my $start_t = time();
21    
22  my $pidfile = new File::Pid;  my $pidfile = new File::Pid;
23    
24  if (my $pid = $pidfile->running ) {  if (my $pid = $pidfile->running ) {
# Line 36  my %Conf = $bpc->Conf(); Line 38  my %Conf = $bpc->Conf();
38  my $TopDir = $bpc->TopDir();  my $TopDir = $bpc->TopDir();
39  my $beenThere = {};  my $beenThere = {};
40    
41  my $dsn = "dbi:SQLite:dbname=$TopDir/$Conf{SearchDB}";  my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n";
42  my $user = '';  my $user = $Conf{SearchUser} || '';
   
 # DEBUG option!  
 ($dsn,$user) = qw/dbi:Pg:dbname=backuppc dpavlin/;  
43    
44  my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 });  my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 });
45    
# Line 66  if ($opt{c}) { Line 65  if ($opt{c}) {
65                  my $index = shift || return;                  my $index = shift || return;
66                  my ($table,$col,$unique) = split(/_/, $index);                  my ($table,$col,$unique) = split(/_/, $index);
67                  $unique ||= '';                  $unique ||= '';
68                    $index =~ s/,/_/g;
69                  $dbh->do(qq{ create $unique index $index on $table($col) });                  $dbh->do(qq{ create $unique index $index on $table($col) });
70          }          }
71    
# Line 99  if ($opt{c}) { Line 99  if ($opt{c}) {
99                  );                              );            
100          });          });
101    
102          do_index('backups_num_unique');          do_index('backups_hostid,num_unique');
103    
104          $dbh->do(qq{          $dbh->do(qq{
105                  create table dvds (                  create table dvds (
# Line 114  if ($opt{c}) { Line 114  if ($opt{c}) {
114                  create table files (                  create table files (
115                          ID      SERIAL          PRIMARY KEY,                            ID      SERIAL          PRIMARY KEY,  
116                          shareID INTEGER         NOT NULL references shares(id),                          shareID INTEGER         NOT NULL references shares(id),
117                          backupNum  INTEGER      NOT NULL references backups(num),                          backupNum  INTEGER      NOT NULL,
118                          name       VARCHAR(255) NOT NULL,                          name       VARCHAR(255) NOT NULL,
119                          path       VARCHAR(255) NOT NULL,                          path       VARCHAR(255) NOT NULL,
120                          fullpath   VARCHAR(255) NOT NULL,                          fullpath   VARCHAR(255) NOT NULL,
# Line 156  if ($opt{d}) { Line 156  if ($opt{d}) {
156          }          }
157          print " done...\n";          print " done...\n";
158    
159          eval { $dbh->commit; };          $dbh->commit;
160  }  }
161    
162  if ($opt{v}) {  if ($opt{v}) {
# Line 198  INSERT INTO files Line 198  INSERT INTO files
198          VALUES (?,?,?,?,?,?,?,?)          VALUES (?,?,?,?,?,?,?,?)
199  });  });
200    
201    sub fmt_time {
202            my $t = shift || return;
203            my $out = "";
204            my ($ss,$mm,$hh) = gmtime($t);
205            $out .= "${hh}h" if ($hh);
206            $out .= sprintf("%02d:%02d", $mm,$ss);
207            return $out;
208    }
209    
210  foreach my $host_key (keys %{$hosts}) {  foreach my $host_key (keys %{$hosts}) {
211    
212          my $hostname = $hosts->{$host_key}->{'host'} || die "can't find host for $host_key";          my $hostname = $hosts->{$host_key}->{'host'} || die "can't find host for $host_key";
# Line 232  foreach my $host_key (keys %{$hosts}) { Line 241  foreach my $host_key (keys %{$hosts}) {
241                  print $hosts->{$host_key}->{'host'},                  print $hosts->{$host_key}->{'host'},
242                          "\t#$backupNum\t", $backup->{type} || '?', " ",                          "\t#$backupNum\t", $backup->{type} || '?', " ",
243                          $backup->{nFilesNew} || '?', "/", $backup->{nFiles} || '?',                          $backup->{nFilesNew} || '?', "/", $backup->{nFiles} || '?',
244                          " files\n";                          " files (date: ",
245                            strftime($t_fmt,localtime($backup->{startTime})),
246                            " dur: ",
247                            fmt_time($backup->{endTime} - $backup->{startTime}),
248                            ")\n";
249    
250                  $sth->{backups_broj}->execute($hostID, $backupNum);                  $sth->{backups_broj}->execute($hostID, $backupNum);
251                  my ($broj) = $sth->{backups_broj}->fetchrow_array();                  my ($broj) = $sth->{backups_broj}->fetchrow_array();
# Line 255  foreach my $host_key (keys %{$hosts}) { Line 268  foreach my $host_key (keys %{$hosts}) {
268                          $shareID = getShareID($share, $hostID, $hostname);                          $shareID = getShareID($share, $hostID, $hostname);
269                                    
270                          my ($f, $nf, $d, $nd) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID);                          my ($f, $nf, $d, $nd) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID);
271                          printf(" %d/%d files %d/%d dirs [%.2f/s]\n",                          my $dur = (time() - $t) || 1;
272                            printf(" %d/%d files %d/%d dirs [%.2f/s dur: %s]\n",
273                                  $nf, $f, $nd, $d,                                  $nf, $f, $nd, $d,
274                                  ( ($f+$d) / ((time() - $t) || 1) )                                  ( ($f+$d) / $dur ),
275                                    fmt_time($dur)
276                          );                          );
277                          $dbh->commit();                          $dbh->commit();
278                  }                  }
# Line 268  undef $sth; Line 283  undef $sth;
283  $dbh->commit();  $dbh->commit();
284  $dbh->disconnect();  $dbh->disconnect();
285    
286    print "total duration: ",fmt_time(time() - $start_t),"\n";
287    
288  $pidfile->remove;  $pidfile->remove;
289    
290  sub getShareID() {  sub getShareID() {

Legend:
Removed from v.49  
changed lines
  Added in v.57

  ViewVC Help
Powered by ViewVC 1.1.26