/[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 104 by dpavlin, Wed Aug 31 11:05:26 2005 UTC revision 130 by dpavlin, Fri Sep 23 08:54:10 2005 UTC
# Line 11  use Getopt::Std; Line 11  use Getopt::Std;
11  use Time::HiRes qw/time/;  use Time::HiRes qw/time/;
12  use File::Pid;  use File::Pid;
13  use POSIX qw/strftime/;  use POSIX qw/strftime/;
14    use BackupPC::SearchLib;
15    
16  use constant BPC_FTYPE_DIR => 5;  use constant BPC_FTYPE_DIR => 5;
17  use constant EST_CHUNK => 100000;  use constant EST_CHUNK => 100000;
# Line 41  my $beenThere = {}; Line 42  my $beenThere = {};
42    
43  my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n";  my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n";
44  my $user = $Conf{SearchUser} || '';  my $user = $Conf{SearchUser} || '';
 my $index_path = $Conf{HyperEstraierIndex};  
 $index_path = $TopDir . '/' . $index_path;  
 $index_path =~ s#//#/#g;  
 if ($index_path) {  
         use HyperEstraier;  
 }  
45    
46    my $use_hest = $Conf{HyperEstraierIndex};
47    my ($index_path, $index_node_url) = BackupPC::SearchLib::getHyperEstraier_url($use_hest);
48    
49  my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 });  my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 });
50    
# Line 88  sub curr_time { Line 85  sub curr_time {
85  }  }
86    
87  my $hest_db;  my $hest_db;
88    my $hest_node;
89    
90  sub signal {  sub signal {
91          my($sig) = @_;          my($sig) = @_;
# Line 106  sub hest_update { Line 104  sub hest_update {
104    
105          my ($host_id, $share_id, $num) = @_;          my ($host_id, $share_id, $num) = @_;
106    
107            unless ($use_hest) {
108                    print STDERR "HyperEstraier support not enabled in configuration\n";
109                    return;
110            }
111    
112          print curr_time," updating HyperEstraier:";          print curr_time," updating HyperEstraier:";
113    
114          my $t = time();          my $t = time();
# Line 113  sub hest_update { Line 116  sub hest_update {
116          my $offset = 0;          my $offset = 0;
117          my $added = 0;          my $added = 0;
118    
119          print " opening index $index_path";          print " opening index $use_hest";
120          $hest_db = HyperEstraier::Database->new();          if ($index_path) {
121          $hest_db->open($index_path, $HyperEstraier::Database::DBWRITER | $HyperEstraier::Database::DBCREAT);                  $hest_db = HyperEstraier::Database->new();
122                    $hest_db->open($TopDir . $index_path, $HyperEstraier::Database::DBWRITER | $HyperEstraier::Database::DBCREAT);
123          print " increment is " . EST_CHUNK . " files";                  print " directly";
124            } elsif ($index_node_url) {
125                    $hest_node ||= HyperEstraier::Node->new($index_node_url);
126                    $hest_node->set_auth('admin', 'admin');
127                    print " via node URL";
128            } else {
129                    die "don't know how to use HyperEstraier Index $use_hest";
130            }
131            print " increment is " . EST_CHUNK . " files:";
132    
133          my $results = 0;          my $results = 0;
134    
# Line 163  sub hest_update { Line 174  sub hest_update {
174                  $results = $sth->rows;                  $results = $sth->rows;
175    
176                  if ($results == 0) {                  if ($results == 0) {
177                          print " - no more files\n";                          print " - no new files\n";
178                          last;                          last;
179                  }                  }
180    
# Line 179  sub hest_update { Line 190  sub hest_update {
190                          my $fid = $row->{'fid'} || die "no fid?";                          my $fid = $row->{'fid'} || die "no fid?";
191                          my $uri = 'file:///' . $fid;                          my $uri = 'file:///' . $fid;
192    
193                          my $id = $hest_db->uri_to_id($uri);                          my $id = ($hest_db || $hest_node)->uri_to_id($uri);
194                          next unless ($id == -1);                          next unless ($id == -1);
195    
196                          # create a document object                          # create a document object
# Line 203  sub hest_update { Line 214  sub hest_update {
214                          print STDERR $doc->dump_draft,"\n" if ($debug > 1);                          print STDERR $doc->dump_draft,"\n" if ($debug > 1);
215    
216                          # register the document object to the database                          # register the document object to the database
217                          $hest_db->put_doc($doc, $HyperEstraier::Database::PDCLEAN);                          if ($hest_db) {
218                                    $hest_db->put_doc($doc, $HyperEstraier::Database::PDCLEAN);
219                            } elsif ($hest_node) {
220                                    $hest_node->put_doc($doc);
221                            } else {
222                                    die "not supported";
223                            }
224                          $added++;                          $added++;
225                  }                  }
226    
227                  print " $added";                  print " $added";
228                  $hest_db->sync();                  $hest_db->sync() if ($index_path);
229    
230                  $offset += EST_CHUNK;                  $offset += EST_CHUNK;
231    
232          } while ($results == EST_CHUNK);          } while ($results == EST_CHUNK);
233    
234          print ", close";          if ($index_path) {
235          $hest_db->close();                  print ", close";
236                    $hest_db->close();
237            }
238    
239          my $dur = (time() - $t) || 1;          my $dur = (time() - $t) || 1;
240          printf(" [%.2f/s dur: %s]\n",          printf(" [%.2f/s dur: %s]\n",
# Line 266  if ($opt{c}) { Line 285  if ($opt{c}) {
285                          localpath VARCHAR(200)                                localpath VARCHAR(200)      
286                  );                              );            
287          });          });
288    
289            $dbh->do(qq{
290                    create table dvds (
291                            ID      SERIAL          PRIMARY KEY,
292                            num     INTEGER         NOT NULL,
293                            name    VARCHAR(255)    NOT NULL,
294                            mjesto  VARCHAR(255)
295                    );
296            });
297                    
298          $dbh->do(qq{          $dbh->do(qq{
299                  create table backups (                  create table backups (
# Line 281  if ($opt{c}) { Line 309  if ($opt{c}) {
309    
310          #do_index('backups_hostid,num_unique');          #do_index('backups_hostid,num_unique');
311    
         $dbh->do(qq{  
                 create table dvds (  
                         ID      SERIAL          PRIMARY KEY,  
                         num     INTEGER         NOT NULL,  
                         name    VARCHAR(255)    NOT NULL,  
                         mjesto  VARCHAR(255)  
                 );  
         });  
312    
313          $dbh->do(qq{              $dbh->do(qq{    
314                  create table files (                  create table files (
# Line 299  if ($opt{c}) { Line 319  if ($opt{c}) {
319                          path       VARCHAR(255) NOT NULL,                          path       VARCHAR(255) NOT NULL,
320                          date       integer      NOT NULL,                          date       integer      NOT NULL,
321                          type       INTEGER      NOT NULL,                          type       INTEGER      NOT NULL,
322                          size       INTEGER      NOT NULL,                          size       INTEGER      NOT NULL
                         dvdid      INTEGER      references dvds(id)      
323                  );                  );
324          });          });
325    
326    
327            $dbh->do( qq{
328                    create table archive
329                    (
330                            id                      int not null,
331                            dvd_nr          int not null,
332                            note            text,
333                            username        varchar(20) not null,
334                            date            timestamp,
335                            primary key(id)
336                    );      
337            }
338            );
339    
340            $dbh->do( qq{
341                    create table archive_backup
342                    (
343                            archive_id      int not null,
344                            backup_id       int not null,
345                            status          text,
346                            primary key(archive_id, backup_id)
347                    );
348            });
349    
350            $dbh->do( qq{
351                    create table workflows(
352                            id                      int not null,
353                            step_id         int not null,
354                            start           timestamp,
355                            stop            timestamp,
356                            username        varchar(20),
357                            archive_id      int not null,
358                            running         boolean default true,
359                            primary key(id)
360                    );
361            });
362    
363            $dbh->do( qq{
364                    create table workflow_step
365                    (
366                            step_id         int not null,
367                            code            text,
368                            next_step       int,
369                            stop            boolean default false,
370                            primary key(step_id)
371                    );
372            });
373    
374            $dbh->do( qq{
375                            alter table workflow_step
376                                    add constraint fk_workflow_next_step
377                                    foreign key(next_step)
378                                    references workflow_step(step_id);
379            });
380    
381            $dbh->do( qq{
382                    alter table workflows
383                            add constraint fk_workflows_step_id
384                            foreign key(step_id)
385                            references workflow_step(step_id);
386            });
387            
388            $dbh->do( qq{
389                    alter table workflows
390                            add constraint fk_workflows_archive_id
391                            foreign key(archive_id)
392                            references archive(id);
393            });
394    
395            $dbh->do( qq{
396                    create table workflow_log
397                    (
398                            workflow_id             int not null,
399                            step_id                 int not null,
400                            date                    timestamp not null,
401                            status                  text,
402                            primary key(workflow_id, step_id)
403                    );
404            });
405    
406            $dbh->do( qq{
407                    alter table workflow_log
408                            add constraint fk_workflow_log_workflow_id
409                            foreign key (workflow_id)
410                            references workflows(id);
411                    });
412            
413            $dbh->do( qq{
414                    alter table workflow_log
415                            add constraint fk_workflow_log_step_id
416                            foreign key (step_id)
417                            references      workflow_step(step_id);
418                    });
419    
420          print "creating indexes:";          print "creating indexes:";
421    
422          foreach my $index (qw(          foreach my $index (qw(
# Line 436  foreach my $host_key (keys %{$hosts}) { Line 549  foreach my $host_key (keys %{$hosts}) {
549                                  $hostID,                                  $hostID,
550                                  $backupNum,                                  $backupNum,
551                                  $backup->{'endTime'},                                  $backup->{'endTime'},
552                                  $backup->{'type'},                                  substr($backup->{'type'},0,4),
553                                  $shareID,                                  $shareID,
554                                  $size,                                  $size,
555                          );                          );
# Line 452  foreach my $host_key (keys %{$hosts}) { Line 565  foreach my $host_key (keys %{$hosts}) {
565                                  fmt_time($dur)                                  fmt_time($dur)
566                          );                          );
567    
568                          hest_update($hostID, $shareID, $backupNum);                          hest_update($hostID, $shareID, $backupNum) if ($nf + $nd > 0);
569                  }                  }
570    
571          }          }

Legend:
Removed from v.104  
changed lines
  Added in v.130

  ViewVC Help
Powered by ViewVC 1.1.26