/[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 82 by dpavlin, Sun Aug 28 09:12:54 2005 UTC revision 86 by dpavlin, Sun Aug 28 12:35:59 2005 UTC
# Line 65  if ($opt{v}) { Line 65  if ($opt{v}) {
65          $debug = $opt{v};          $debug = $opt{v};
66  }  }
67    
68    #---- subs ----
69    
70    sub fmt_time {
71            my $t = shift || return;
72            my $out = "";
73            my ($ss,$mm,$hh) = gmtime($t);
74            $out .= "${hh}h" if ($hh);
75            $out .= sprintf("%02d:%02d", $mm,$ss);
76            return $out;
77    }
78    
79    sub curr_time {
80            return strftime($t_fmt,localtime());
81    }
82    
83    #---- /subs ----
84    
85  ## update index ##  ## update index ##
86  if ($opt{i}) {  if ($opt{i}) {
87    
88          print "updating HyperEstraier files ";          print curr_time," updating HyperEstraier: files";
89    
90            my $t = time();
91                    
92          my $sth = $dbh->prepare(qq{          my $sth = $dbh->prepare(qq{
93                  SELECT                  SELECT
94                          files.id                        AS fid,                          files.id                        AS fid,
95                          hosts.name                      AS hname,                          hosts.name                      AS hname,
96                          shares.name                     AS sname,                          shares.name                     AS sname,
97                          shares.share                    AS sharename,                          -- shares.share                 AS sharename,
98                          files.backupNum                 AS backupNum,                          files.backupnum                 AS backupnum,
99                          files.name                      AS filename,                          -- files.name                   AS filename,
100                          files.path                      AS filepath,                          files.path                      AS filepath,
101                          files.date                      AS date,                          files.date                      AS date,
102                          files.type                      AS filetype,                          files.type                      AS filetype,
103                          files.size                      AS size,                          files.size                      AS size,
104                          files.shareid                   AS shareid                          files.shareid                   AS shareid,
105                            backups.date                    AS backup_date
106                  FROM files                  FROM files
107                          INNER JOIN shares       ON files.shareID=shares.ID                          INNER JOIN shares       ON files.shareID=shares.ID
108                          INNER JOIN hosts        ON hosts.ID = shares.hostID                          INNER JOIN hosts        ON hosts.ID = shares.hostID
# Line 90  if ($opt{i}) { Line 110  if ($opt{i}) {
110          });          });
111    
112          $sth->execute();          $sth->execute();
113            my $results = $sth->rows;
114    
115          my $dot = int($sth->rows / 15);          my $dot = int($results / 15);
116    
117          print $sth->rows, " files ($dot/#) ";          print " $results ($dot/#)";
118    
119          sub fmt_date {          sub fmt_date {
120                  my $t = shift || return;                  my $t = shift || return;
# Line 103  if ($opt{i}) { Line 124  if ($opt{i}) {
124          }          }
125    
126          my $i = 0;          my $i = 0;
127          my $max = int($sth->rows / $dot);          my $max = int($results / $dot);
128    
129          $index_path = $TopDir . '/' . $index_path;          $index_path = $TopDir . '/' . $index_path;
130          $index_path =~ s#//#/#g;          $index_path =~ s#//#/#g;
131    
132          print "index $index_path...";          print " index $index_path...";
133          use HyperEstraier;          use HyperEstraier;
134          my $db = HyperEstraier::Database->new();          my $db = HyperEstraier::Database->new();
135          $db->open($index_path, $HyperEstraier::Database::DBWRITER | $HyperEstraier::Database::DBCREAT);          $db->open($index_path, $HyperEstraier::Database::DBWRITER | $HyperEstraier::Database::DBCREAT);
# Line 122  if ($opt{i}) { Line 143  if ($opt{i}) {
143                  # add attributes to the document object                  # add attributes to the document object
144                  $doc->add_attr('@uri', 'file:///' . $row->{'fid'});                  $doc->add_attr('@uri', 'file:///' . $row->{'fid'});
145    
146                  foreach my $c (qw/fid hname sname sharename backupNum filename filepath shareid/) {                  foreach my $c (@{ $sth->{NAME} }) {
147                          $doc->add_attr($c, $row->{$c}) if ($row->{$c});                          $doc->add_attr($c, $row->{$c}) if ($row->{$c});
148                  }                  }
149    
150                  $doc->add_attr('date', fmt_date($row->{'date'}));                  #$doc->add_attr('@cdate', fmt_date($row->{'date'}));
151    
152                  # add the body text to the document object                  # add the body text to the document object
153                  my $path = $row->{'filepath'};                  my $path = $row->{'filepath'};
# Line 149  if ($opt{i}) { Line 170  if ($opt{i}) {
170    
171          print "sync";          print "sync";
172          $db->sync();          $db->sync();
173          print " close\n";          print " close";
174          $db->close();          $db->close();
175    
176            my $dur = (time() - $t) || 1;
177            printf(" [%.2f/s dur: %s]\n",
178                    ( $results / $dur ),
179                    fmt_time($dur)
180            );
181    
182          exit;          exit;
183  }  }
184    
# Line 291  INSERT INTO files Line 318  INSERT INTO files
318          VALUES (?,?,?,?,?,?,?)          VALUES (?,?,?,?,?,?,?)
319  });  });
320    
 sub fmt_time {  
         my $t = shift || return;  
         my $out = "";  
         my ($ss,$mm,$hh) = gmtime($t);  
         $out .= "${hh}h" if ($hh);  
         $out .= sprintf("%02d:%02d", $mm,$ss);  
         return $out;  
 }  
   
321  foreach my $host_key (keys %{$hosts}) {  foreach my $host_key (keys %{$hosts}) {
322    
323          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 355  foreach my $host_key (keys %{$hosts}) { Line 373  foreach my $host_key (keys %{$hosts}) {
373                          next if ($count > 0);                          next if ($count > 0);
374    
375                          # dump some log                          # dump some log
376                          print strftime($t_fmt,localtime())," ", $share;                          print curr_time," ", $share;
377    
378                          my ($f, $nf, $d, $nd, $size) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID);                          my ($f, $nf, $d, $nd, $size) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID);
379    

Legend:
Removed from v.82  
changed lines
  Added in v.86

  ViewVC Help
Powered by ViewVC 1.1.26