/[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 99 by dpavlin, Tue Aug 30 14:45:33 2005 UTC revision 116 by dpavlin, Sun Sep 11 12:39:24 2005 UTC
# Line 41  my $beenThere = {}; Line 41  my $beenThere = {};
41    
42  my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n";  my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n";
43  my $user = $Conf{SearchUser} || '';  my $user = $Conf{SearchUser} || '';
44  my $index_path = $Conf{HyperEstraierIndex};  
45  $index_path = $TopDir . '/' . $index_path;  my $use_hest = $Conf{HyperEstraierIndex};
46  $index_path =~ s#//#/#g;  my ($index_path, $index_node_url);
47  if ($index_path) {  if ($use_hest) {
48          use HyperEstraier;          use HyperEstraier;
49            if ($use_hest =~ m#^http://#) {
50                    $index_node_url = $use_hest;
51            } else {
52                    $index_path = $TopDir . '/' . $index_path;
53                    $index_path =~ s#//#/#g;
54            }
55  }  }
56    print "-- $use_hest : $index_path OR $index_node_url --\n";
57    
58    
59  my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 });  my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 });
# Line 88  sub curr_time { Line 95  sub curr_time {
95  }  }
96    
97  my $hest_db;  my $hest_db;
98    my $hest_node;
99    
100  sub signal {  sub signal {
101          my($sig) = @_;          my($sig) = @_;
# Line 106  sub hest_update { Line 114  sub hest_update {
114    
115          my ($host_id, $share_id, $num) = @_;          my ($host_id, $share_id, $num) = @_;
116    
117            unless ($use_hest) {
118                    print STDERR "HyperEstraier support not enabled in configuration\n";
119                    return;
120            }
121    
122          print curr_time," updating HyperEstraier:";          print curr_time," updating HyperEstraier:";
123    
124          my $t = time();          my $t = time();
# Line 113  sub hest_update { Line 126  sub hest_update {
126          my $offset = 0;          my $offset = 0;
127          my $added = 0;          my $added = 0;
128    
129          print " opening index $index_path";          print " opening index $use_hest";
130          $hest_db = HyperEstraier::Database->new();          if ($index_path) {
131          $hest_db->open($index_path, $HyperEstraier::Database::DBWRITER | $HyperEstraier::Database::DBCREAT);                  $hest_db = HyperEstraier::Database->new();
132                    $hest_db->open($index_path, $HyperEstraier::Database::DBWRITER | $HyperEstraier::Database::DBCREAT);
133          print " increment is " . EST_CHUNK . " files";                  print " directly";
134            } elsif ($index_node_url) {
135                    $hest_node ||= HyperEstraier::Node->new($index_node_url);
136                    $hest_node->set_auth('admin', 'admin');
137                    print " via node URL";
138            } else {
139                    die "don't know how to use HyperEstraier Index $use_hest";
140            }
141            print " increment is " . EST_CHUNK . " files:";
142    
143          my $results = 0;          my $results = 0;
144    
145          do {          do {
146    
147                  my $where = '';                  my $where = '';
148                    my @data;
149                  if ($host_id && $share_id && $num) {                  if ($host_id && $share_id && $num) {
150                          $where = qq{                          $where = qq{
151                          WHERE                          WHERE
# Line 131  sub hest_update { Line 153  sub hest_update {
153                                  shares.id = ? AND                                  shares.id = ? AND
154                                  files.backupnum = ?                                  files.backupnum = ?
155                          };                          };
156                            @data = ( $host_id, $share_id, $num );
157                  }                  }
158    
159                  my $limit = sprintf('LIMIT '.EST_CHUNK.' OFFSET %d', $offset);                  my $limit = sprintf('LIMIT '.EST_CHUNK.' OFFSET %d', $offset);
# Line 157  sub hest_update { Line 180  sub hest_update {
180                          $limit                          $limit
181                  });                  });
182    
183                  $sth->execute(@_);                  $sth->execute(@data);
184                  $results = $sth->rows;                  $results = $sth->rows;
185    
186                  if ($results == 0) {                  if ($results == 0) {
187                          print " - no more files\n";                          print " - no new files\n";
188                          last;                          last;
189                  }                  }
190    
# Line 177  sub hest_update { Line 200  sub hest_update {
200                          my $fid = $row->{'fid'} || die "no fid?";                          my $fid = $row->{'fid'} || die "no fid?";
201                          my $uri = 'file:///' . $fid;                          my $uri = 'file:///' . $fid;
202    
203                          my $id = $hest_db->uri_to_id($uri);                          my $id = ($hest_db || $hest_node)->uri_to_id($uri);
204                          next unless ($id == -1);                          next unless ($id == -1);
205    
206                          # create a document object                          # create a document object
# Line 201  sub hest_update { Line 224  sub hest_update {
224                          print STDERR $doc->dump_draft,"\n" if ($debug > 1);                          print STDERR $doc->dump_draft,"\n" if ($debug > 1);
225    
226                          # register the document object to the database                          # register the document object to the database
227                          $hest_db->put_doc($doc, $HyperEstraier::Database::PDCLEAN);                          if ($hest_db) {
228                                    $hest_db->put_doc($doc, $HyperEstraier::Database::PDCLEAN);
229                            } elsif ($hest_node) {
230                                    $hest_node->put_doc($doc);
231                            } else {
232                                    die "not supported";
233                            }
234                          $added++;                          $added++;
235                  }                  }
236    
237                  print " $added";                  print " $added";
238                  $hest_db->sync();                  $hest_db->sync() if ($index_path);
239    
240                  $offset += EST_CHUNK;                  $offset += EST_CHUNK;
241    
242          } while ($results == EST_CHUNK);          } while ($results == EST_CHUNK);
243    
244          print ", close";          if ($index_path) {
245          $hest_db->close();                  print ", close";
246                    $hest_db->close();
247            }
248    
249          my $dur = (time() - $t) || 1;          my $dur = (time() - $t) || 1;
250          printf(" [%.2f/s dur: %s]\n",          printf(" [%.2f/s dur: %s]\n",
# Line 450  foreach my $host_key (keys %{$hosts}) { Line 481  foreach my $host_key (keys %{$hosts}) {
481                                  fmt_time($dur)                                  fmt_time($dur)
482                          );                          );
483    
484                          hest_update($hostID, $shareID, $backupNum);                          hest_update($hostID, $shareID, $backupNum) if ($nf + $nd > 0);
485                  }                  }
486    
487          }          }

Legend:
Removed from v.99  
changed lines
  Added in v.116

  ViewVC Help
Powered by ViewVC 1.1.26