/[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 98 by dpavlin, Tue Aug 30 14:19:54 2005 UTC revision 117 by dpavlin, Sun Sep 11 13:05:06 2005 UTC
# Line 13  use File::Pid; Line 13  use File::Pid;
13  use POSIX qw/strftime/;  use POSIX qw/strftime/;
14    
15  use constant BPC_FTYPE_DIR => 5;  use constant BPC_FTYPE_DIR => 5;
16  use constant EST_CHUNK => 10000;  use constant EST_CHUNK => 100000;
17    
18  my $debug = 0;  my $debug = 0;
19  $|=1;  $|=1;
# 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} || '';
 my $index_path = $Conf{HyperEstraierIndex};  
 $index_path = $TopDir . '/' . $index_path;  
 $index_path =~ s#//#/#g;  
 if ($index_path) {  
         use HyperEstraier;  
 }  
44    
45    my $use_hest = $Conf{HyperEstraierIndex};
46    my ($index_path, $index_node_url) = getHyperEstraier_url($use_hest);
47    
48  my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 });  my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 });
49    
# Line 88  sub curr_time { Line 84  sub curr_time {
84  }  }
85    
86  my $hest_db;  my $hest_db;
87    my $hest_node;
88    
89  sub signal {  sub signal {
90          my($sig) = @_;          my($sig) = @_;
# Line 106  sub hest_update { Line 103  sub hest_update {
103    
104          my ($host_id, $share_id, $num) = @_;          my ($host_id, $share_id, $num) = @_;
105    
106            unless ($use_hest) {
107                    print STDERR "HyperEstraier support not enabled in configuration\n";
108                    return;
109            }
110    
111          print curr_time," updating HyperEstraier:";          print curr_time," updating HyperEstraier:";
112    
113          my $t = time();          my $t = time();
# Line 113  sub hest_update { Line 115  sub hest_update {
115          my $offset = 0;          my $offset = 0;
116          my $added = 0;          my $added = 0;
117    
118          print " opening index $index_path";          print " opening index $use_hest";
119          $hest_db = HyperEstraier::Database->new();          if ($index_path) {
120          $hest_db->open($index_path, $HyperEstraier::Database::DBWRITER | $HyperEstraier::Database::DBCREAT);                  $hest_db = HyperEstraier::Database->new();
121                    $hest_db->open($index_path, $HyperEstraier::Database::DBWRITER | $HyperEstraier::Database::DBCREAT);
122                    print " directly";
123            } elsif ($index_node_url) {
124                    $hest_node ||= HyperEstraier::Node->new($index_node_url);
125                    $hest_node->set_auth('admin', 'admin');
126                    print " via node URL";
127            } else {
128                    die "don't know how to use HyperEstraier Index $use_hest";
129            }
130            print " increment is " . EST_CHUNK . " files:";
131    
132          my $results = 0;          my $results = 0;
133    
134          do {          do {
135    
136                  my $where = '';                  my $where = '';
137                    my @data;
138                  if ($host_id && $share_id && $num) {                  if ($host_id && $share_id && $num) {
139                          $where = qq{                          $where = qq{
140                          WHERE                          WHERE
# Line 129  sub hest_update { Line 142  sub hest_update {
142                                  shares.id = ? AND                                  shares.id = ? AND
143                                  files.backupnum = ?                                  files.backupnum = ?
144                          };                          };
145                            @data = ( $host_id, $share_id, $num );
146                  }                  }
147    
148                  my $limit = sprintf('LIMIT '.EST_CHUNK.' OFFSET %d', $offset);                  my $limit = sprintf('LIMIT '.EST_CHUNK.' OFFSET %d', $offset);
# Line 155  sub hest_update { Line 169  sub hest_update {
169                          $limit                          $limit
170                  });                  });
171    
172                  $sth->execute(@_);                  $sth->execute(@data);
173                  $results = $sth->rows;                  $results = $sth->rows;
174    
175                  if ($results == 0) {                  if ($results == 0) {
176                          print " - no more files\n";                          print " - no new files\n";
177                          last;                          last;
178                  }                  }
179    
# Line 175  sub hest_update { Line 189  sub hest_update {
189                          my $fid = $row->{'fid'} || die "no fid?";                          my $fid = $row->{'fid'} || die "no fid?";
190                          my $uri = 'file:///' . $fid;                          my $uri = 'file:///' . $fid;
191    
192                          my $id = $hest_db->uri_to_id($uri);                          my $id = ($hest_db || $hest_node)->uri_to_id($uri);
193                          next unless ($id == -1);                          next unless ($id == -1);
194    
195                          # create a document object                          # create a document object
# Line 199  sub hest_update { Line 213  sub hest_update {
213                          print STDERR $doc->dump_draft,"\n" if ($debug > 1);                          print STDERR $doc->dump_draft,"\n" if ($debug > 1);
214    
215                          # register the document object to the database                          # register the document object to the database
216                          $hest_db->put_doc($doc, $HyperEstraier::Database::PDCLEAN);                          if ($hest_db) {
217                                    $hest_db->put_doc($doc, $HyperEstraier::Database::PDCLEAN);
218                            } elsif ($hest_node) {
219                                    $hest_node->put_doc($doc);
220                            } else {
221                                    die "not supported";
222                            }
223                          $added++;                          $added++;
224                  }                  }
225    
226                  print " $added";                  print " $added";
227                  $hest_db->sync();                  $hest_db->sync() if ($index_path);
228    
229                  $offset += EST_CHUNK;                  $offset += EST_CHUNK;
230    
231          } while ($results == EST_CHUNK);          } while ($results == EST_CHUNK);
232    
233          print ", close";          if ($index_path) {
234          $hest_db->close();                  print ", close";
235                    $hest_db->close();
236            }
237    
238          my $dur = (time() - $t) || 1;          my $dur = (time() - $t) || 1;
239          printf(" [%.2f/s dur: %s]\n",          printf(" [%.2f/s dur: %s]\n",
# Line 448  foreach my $host_key (keys %{$hosts}) { Line 470  foreach my $host_key (keys %{$hosts}) {
470                                  fmt_time($dur)                                  fmt_time($dur)
471                          );                          );
472    
473                          hest_update($hostID, $shareID, $backupNum);                          hest_update($hostID, $shareID, $backupNum) if ($nf + $nd > 0);
474                  }                  }
475    
476          }          }

Legend:
Removed from v.98  
changed lines
  Added in v.117

  ViewVC Help
Powered by ViewVC 1.1.26