/[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 136 by dpavlin, Fri Sep 23 15:04:37 2005 UTC revision 315 by dpavlin, Sun Jan 29 18:08:52 2006 UTC
# Line 12  use Time::HiRes qw/time/; Line 12  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;  use BackupPC::SearchLib;
15    use Cwd qw/abs_path/;
16    
17  use constant BPC_FTYPE_DIR => 5;  use constant BPC_FTYPE_DIR => 5;
18  use constant EST_CHUNK => 100000;  use constant EST_CHUNK => 4096;
19    
20    # daylight saving time change offset for 1h
21    my $dst_offset = 60 * 60;
22    
23  my $debug = 0;  my $debug = 0;
24  $|=1;  $|=1;
25    
26  my $start_t = time();  my $start_t = time();
27    
28  my $pidfile = new File::Pid;  my $pid_path = abs_path($0);
29    $pid_path =~ s/\W+/_/g;
30    
31    my $pidfile = new File::Pid({
32            file => "/tmp/$pid_path",
33    });
34    
35  if (my $pid = $pidfile->running ) {  if (my $pid = $pidfile->running ) {
36          die "$0 already running: $pid\n";          die "$0 already running: $pid\n";
# Line 29  if (my $pid = $pidfile->running ) { Line 38  if (my $pid = $pidfile->running ) {
38          $pidfile->remove;          $pidfile->remove;
39          $pidfile = new File::Pid;          $pidfile = new File::Pid;
40  }  }
 $pidfile->write;  
41  print STDERR "$0 using pid ",$pidfile->pid," file ",$pidfile->file,"\n";  print STDERR "$0 using pid ",$pidfile->pid," file ",$pidfile->file,"\n";
42    $pidfile->write;
43    
44  my $t_fmt = '%Y-%m-%d %H:%M:%S';  my $t_fmt = '%Y-%m-%d %H:%M:%S';
45    
# Line 43  my $beenThere = {}; Line 52  my $beenThere = {};
52  my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n";  my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n";
53  my $user = $Conf{SearchUser} || '';  my $user = $Conf{SearchUser} || '';
54    
55  my $use_hest = $Conf{HyperEstraierIndex};  my $index_node_url = $Conf{HyperEstraierIndex};
 my ($index_path, $index_node_url) = BackupPC::SearchLib::getHyperEstraier_url($use_hest);  
56    
57  my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 });  my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 });
58    
59  my %opt;  my %opt;
60    
61  if ( !getopts("cdm:v:ij", \%opt ) ) {  if ( !getopts("cdm:v:ijfq", \%opt ) ) {
62          print STDERR <<EOF;          print STDERR <<EOF;
63  usage: $0 [-c|-d] [-m num] [-v|-v level] [-i]  usage: $0 [-c|-d] [-m num] [-v|-v level] [-i|-j|-f]
64    
65  Options:  Options:
66          -c      create database on first use          -c      create database on first use
# Line 61  Options: Line 69  Options:
69          -v num  set verbosity (debug) level (default $debug)          -v num  set verbosity (debug) level (default $debug)
70          -i      update Hyper Estraier full text index          -i      update Hyper Estraier full text index
71          -j      update full text, don't check existing files          -j      update full text, don't check existing files
72            -f      don't do anything with full text index
73            -q      be quiet for hosts without changes
74    
75  Option -j is variation on -i. It will allow faster initial creation  Option -j is variation on -i. It will allow faster initial creation
76  of full-text index from existing database.  of full-text index from existing database.
77    
78    Option -f will create database which is out of sync with full text index. You
79    will have to re-run $0 with -i to fix it.
80    
81  EOF  EOF
82          exit 1;          exit 1;
83  }  }
# Line 72  EOF Line 85  EOF
85  if ($opt{v}) {  if ($opt{v}) {
86          print "Debug level at $opt{v}\n";          print "Debug level at $opt{v}\n";
87          $debug = $opt{v};          $debug = $opt{v};
88    } elsif ($opt{f}) {
89            print "WARNING: disabling full-text index update. You need to re-run $0 -j !\n";
90            $index_node_url = undef;
91  }  }
92    
93  #---- subs ----  #---- subs ----
# Line 89  sub curr_time { Line 105  sub curr_time {
105          return strftime($t_fmt,localtime());          return strftime($t_fmt,localtime());
106  }  }
107    
 my $hest_db;  
108  my $hest_node;  my $hest_node;
109    
 sub signal {  
         my($sig) = @_;  
         if ($hest_db) {  
                 print "\nCaught a SIG$sig--syncing database and shutting down\n";  
                 $hest_db->sync();  
                 $hest_db->close();  
         }  
         exit(0);  
 }  
   
 $SIG{'INT'}  = \&signal;  
 $SIG{'QUIT'} = \&signal;  
   
110  sub hest_update {  sub hest_update {
111    
112          my ($host_id, $share_id, $num) = @_;          my ($host_id, $share_id, $num) = @_;
113    
114          my $skip_check = $opt{j} && print STDERR "Skipping check for existing files -- this should be used only with initital import\n";          my $skip_check = $opt{j} && print STDERR "Skipping check for existing files -- this should be used only with initital import\n";
115    
116          unless ($use_hest) {          unless (defined($index_node_url)) {
117                  print STDERR "HyperEstraier support not enabled in configuration\n";                  print STDERR "HyperEstraier support not enabled in configuration\n";
118                    $index_node_url = 0;
119                  return;                  return;
120          }          }
121    
122          print curr_time," updating HyperEstraier:";          print curr_time," updating Hyper Estraier:";
123    
124          my $t = time();          my $t = time();
125    
126          my $offset = 0;          my $offset = 0;
127          my $added = 0;          my $added = 0;
128    
129          print " opening index $use_hest";          print " opening index $index_node_url";
130          if ($index_path) {          if ($index_node_url) {
131                  $hest_db = HyperEstraier::Database->new();                  $hest_node ||= Search::Estraier::Node->new(
132                  $hest_db->open($TopDir . $index_path, $HyperEstraier::Database::DBWRITER | $HyperEstraier::Database::DBCREAT);                          url => $index_node_url,
133                  print " directly";                          user => 'admin',
134          } elsif ($index_node_url) {                          passwd => 'admin',
135                  $hest_node ||= HyperEstraier::Node->new($index_node_url);                          croak_on_error => 1,
136                  $hest_node->set_auth('admin', 'admin');                  );
137                  print " via node URL";                  print " via node URL";
138          } else {          } else {
139                  die "don't know how to use HyperEstraier Index $use_hest";                  die "don't know how to use Hyper Estraier Index $index_node_url";
140          }          }
         print " increment is " . EST_CHUNK . " files:";  
141    
142          my $results = 0;          my $results = 0;
143    
# Line 143  sub hest_update { Line 145  sub hest_update {
145    
146                  my $where = '';                  my $where = '';
147                  my @data;                  my @data;
148                  if ($host_id && $share_id && $num) {                  if (defined($host_id) && defined($share_id) && defined($num)) {
149                          $where = qq{                          $where = qq{
150                          WHERE                          WHERE
151                                  hosts.id = ? AND                                  hosts.id = ? AND
# Line 182  sub hest_update { Line 184  sub hest_update {
184    
185                  if ($results == 0) {                  if ($results == 0) {
186                          print " - no new files\n";                          print " - no new files\n";
187                          last;                          return;
188                    } else {
189                            print "...";
190                  }                  }
191    
192                  sub fmt_date {                  sub fmt_date {
# Line 194  sub hest_update { Line 198  sub hest_update {
198    
199                  while (my $row = $sth->fetchrow_hashref()) {                  while (my $row = $sth->fetchrow_hashref()) {
200    
201                          my $fid = $row->{'fid'} || die "no fid?";                          my $uri = $row->{hname} . ':' . $row->{sname} . '#' . $row->{backupnum} . ' ' . $row->{filepath};
                         my $uri = 'file:///' . $fid;  
   
202                          unless ($skip_check) {                          unless ($skip_check) {
203                                  my $id = ($hest_db || $hest_node)->uri_to_id($uri);                                  my $id = $hest_node->uri_to_id($uri);
204                                  next unless ($id == -1);                                  next if ($id && $id == -1);
205                          }                          }
206    
207                          # create a document object                          # create a document object
208                          my $doc = HyperEstraier::Document->new;                          my $doc = Search::Estraier::Document->new;
209    
210                          # add attributes to the document object                          # add attributes to the document object
211                          $doc->add_attr('@uri', $uri);                          $doc->add_attr('@uri', $uri);
212    
213                          foreach my $c (@{ $sth->{NAME} }) {                          foreach my $c (@{ $sth->{NAME} }) {
214                                  $doc->add_attr($c, $row->{$c}) if ($row->{$c});                                  print STDERR "attr $c = $row->{$c}\n" if ($debug > 2);
215                                    $doc->add_attr($c, $row->{$c}) if (defined($row->{$c}));
216                          }                          }
217    
218                          #$doc->add_attr('@cdate', fmt_date($row->{'date'}));                          #$doc->add_attr('@cdate', fmt_date($row->{'date'}));
# Line 223  sub hest_update { Line 226  sub hest_update {
226                          print STDERR $doc->dump_draft,"\n" if ($debug > 1);                          print STDERR $doc->dump_draft,"\n" if ($debug > 1);
227    
228                          # register the document object to the database                          # register the document object to the database
229                          if ($hest_db) {                          if ($hest_node) {
                                 $hest_db->put_doc($doc, $HyperEstraier::Database::PDCLEAN);  
                         } elsif ($hest_node) {  
230                                  $hest_node->put_doc($doc);                                  $hest_node->put_doc($doc);
231                          } else {                          } else {
232                                  die "not supported";                                  die "not supported";
# Line 233  sub hest_update { Line 234  sub hest_update {
234                          $added++;                          $added++;
235                  }                  }
236    
237                  print " $added";                  print "$added";
                 $hest_db->sync() if ($index_path);  
238    
239                  $offset += EST_CHUNK;                  $offset += EST_CHUNK;
240    
241          } while ($results == EST_CHUNK);          } while ($results == EST_CHUNK);
242    
         if ($index_path) {  
                 print ", close";  
                 $hest_db->close();  
         }  
   
243          my $dur = (time() - $t) || 1;          my $dur = (time() - $t) || 1;
244          printf(" [%.2f/s dur: %s]\n",          printf(" [%.2f/s dur: %s]\n",
245                  ( $added / $dur ),                  ( $added / $dur ),
# Line 256  sub hest_update { Line 251  sub hest_update {
251    
252    
253  ## update index ##  ## update index ##
254  if (($opt{i} || $opt{j} || ($index_path && ! -e $index_path)) && !$opt{c}) {  if ( ( $opt{i} || $opt{j} ) && !$opt{c} ) {
255          # update all          # update all
256          print "force update of HyperEstraier index ";          print "force update of Hyper Estraier index ";
         print "importing existing data" unless (-e $index_path);  
257          print "by -i flag" if ($opt{i});          print "by -i flag" if ($opt{i});
258          print "by -j flag" if ($opt{j});          print "by -j flag" if ($opt{j});
259          print "\n";          print "\n";
# Line 270  if (($opt{i} || $opt{j} || ($index_path Line 264  if (($opt{i} || $opt{j} || ($index_path
264  if ($opt{c}) {  if ($opt{c}) {
265          sub do_index {          sub do_index {
266                  my $index = shift || return;                  my $index = shift || return;
267                  my ($table,$col,$unique) = split(/_/, $index);                  my ($table,$col,$unique) = split(/:/, $index);
268                  $unique ||= '';                  $unique ||= '';
269                  $index =~ s/,/_/g;                  $index =~ s/\W+/_/g;
270                    print "$index on $table($col)" . ( $unique ? "u" : "" ) . " ";
271                  $dbh->do(qq{ create $unique index $index on $table($col) });                  $dbh->do(qq{ create $unique index $index on $table($col) });
272          }          }
273    
274          print "creating tables...\n";          print "creating tables...\n";
275          
276          $dbh->do(qq{          $dbh->do( qq{
277                  create table hosts (                  create table hosts (
278                          ID      SERIAL          PRIMARY KEY,                          ID      SERIAL          PRIMARY KEY,
279                          name    VARCHAR(30)     NOT NULL,                          name    VARCHAR(30)     NOT NULL,
280                          IP      VARCHAR(15)                          IP      VARCHAR(15)
281                  );                              );            
282          });  
                 
         $dbh->do(qq{  
283                  create table shares (                  create table shares (
284                          ID      SERIAL          PRIMARY KEY,                          ID      SERIAL          PRIMARY KEY,
285                          hostID  INTEGER         NOT NULL references hosts(id),                          hostID  INTEGER         NOT NULL references hosts(id),
286                          name    VARCHAR(30)     NOT NULL,                          name    VARCHAR(30)     NOT NULL,
287                          share   VARCHAR(200)    NOT NULL,                          share   VARCHAR(200)    NOT NULL
                         localpath VARCHAR(200)        
288                  );                              );            
         });  
289    
         $dbh->do(qq{  
290                  create table dvds (                  create table dvds (
291                          ID      SERIAL          PRIMARY KEY,                          ID      SERIAL          PRIMARY KEY,
292                          num     INTEGER         NOT NULL,                          num     INTEGER         NOT NULL,
293                          name    VARCHAR(255)    NOT NULL,                          name    VARCHAR(255)    NOT NULL,
294                          mjesto  VARCHAR(255)                          mjesto  VARCHAR(255)
295                  );                  );
296          });  
           
         $dbh->do(qq{  
297                  create table backups (                  create table backups (
298                            id      serial,
299                          hostID  INTEGER         NOT NULL references hosts(id),                          hostID  INTEGER         NOT NULL references hosts(id),
300                          num     INTEGER         NOT NULL,                          num     INTEGER         NOT NULL,
301                          date    integer         NOT NULL,                          date    integer         NOT NULL,
302                          type    CHAR(4)         not null,                          type    CHAR(4)         not null,
303                          shareID integer         not null references shares(id),                          shareID integer         not null references shares(id),
304                          size    bigint          not null,                          size    bigint          not null,
305                          PRIMARY KEY(hostID, num, shareID)                          inc_size bigint         not null default -1,
306                            inc_deleted boolean     default false,
307                            parts   integer         not null default 1,
308                            PRIMARY KEY(id)
309                  );                              );            
         });  
   
         #do_index('backups_hostid,num_unique');  
   
310    
         $dbh->do(qq{      
311                  create table files (                  create table files (
312                          ID      SERIAL          PRIMARY KEY,                            ID              SERIAL,
313                          shareID INTEGER         NOT NULL references shares(id),                          shareID         INTEGER NOT NULL references shares(id),
314                          backupNum  INTEGER      NOT NULL,                          backupNum       INTEGER NOT NULL,
315                          name       VARCHAR(255) NOT NULL,                          name            VARCHAR(255) NOT NULL,
316                          path       VARCHAR(255) NOT NULL,                          path            VARCHAR(255) NOT NULL,
317                          date       integer      NOT NULL,                          date            integer NOT NULL,
318                          type       INTEGER      NOT NULL,                          type            INTEGER NOT NULL,
319                          size       INTEGER      NOT NULL                          size            bigint  NOT NULL,
320                            primary key(id)
321                  );                  );
         });  
   
322    
323          $dbh->do( qq{                  create table archive (
324                  create table archive                          id              serial,
                 (  
                         id                      int not null,  
325                          dvd_nr          int not null,                          dvd_nr          int not null,
326                            total_size      bigint default -1,
327                          note            text,                          note            text,
328                          username        varchar(20) not null,                          username        varchar(20) not null,
329                          date            timestamp,                          date            timestamp default now(),
330                          primary key(id)                          primary key(id)
331                  );                        );      
         }  
         );  
332    
333          $dbh->do( qq{                  create table archive_backup (
334                  create table archive_backup                          archive_id      int not null references archive(id) on delete cascade,
335                  (                          backup_id       int not null references backups(id),
                         archive_id      int not null,  
                         backup_id       int not null,  
                         status          text,  
336                          primary key(archive_id, backup_id)                          primary key(archive_id, backup_id)
337                  );                  );
         });  
338    
339          $dbh->do( qq{                  create table archive_burned (
340                  create table workflows(                          archive_id      int references archive(id),
341                          id                      int not null,                          date            timestamp default now(),
342                          step_id         int not null,                          part            int not null default 1,
343                          start           timestamp,                          copy            int not null default 1,
344                          stop            timestamp,                          iso_size bigint default -1
                         username        varchar(20),  
                         archive_id      int not null,  
                         running         boolean default true,  
                         primary key(id)  
                 );  
         });  
   
         $dbh->do( qq{  
                 create table workflow_step  
                 (  
                         step_id         int not null,  
                         code            text,  
                         next_step       int,  
                         stop            boolean default false,  
                         primary key(step_id)  
345                  );                  );
         });  
   
         $dbh->do( qq{  
                         alter table workflow_step  
                                 add constraint fk_workflow_next_step  
                                 foreign key(next_step)  
                                 references workflow_step(step_id);  
         });  
346    
347          $dbh->do( qq{                  create table backup_parts (
348                  alter table workflows                          id serial,
349                          add constraint fk_workflows_step_id                          backup_id int references backups(id),
350                          foreign key(step_id)                          part_nr int not null check (part_nr > 0),
351                          references workflow_step(step_id);                          tar_size bigint not null check (tar_size > 0),
352          });                          size bigint not null check (size > 0),
353                                    md5 text not null,
354          $dbh->do( qq{                          items int not null check (items > 0),
355                  alter table workflows                          date timestamp default now(),
356                          add constraint fk_workflows_archive_id                          primary key(id)
                         foreign key(archive_id)  
                         references archive(id);  
         });  
   
         $dbh->do( qq{  
                 create table workflow_log  
                 (  
                         workflow_id             int not null,  
                         step_id                 int not null,  
                         date                    timestamp not null,  
                         status                  text,  
                         primary key(workflow_id, step_id)  
357                  );                  );
358          });          });
359    
360          $dbh->do( qq{          print "creating indexes: ";
                 alter table workflow_log  
                         add constraint fk_workflow_log_workflow_id  
                         foreign key (workflow_id)  
                         references workflows(id);  
                 });  
           
         $dbh->do( qq{  
                 alter table workflow_log  
                         add constraint fk_workflow_log_step_id  
                         foreign key (step_id)  
                         references      workflow_step(step_id);  
                 });  
   
         print "creating indexes:";  
361    
362          foreach my $index (qw(          foreach my $index (qw(
363                  hosts_name                  hosts:name
364                  backups_hostID                  backups:hostID
365                  backups_num                  backups:num
366                  shares_hostID                  backups:shareID
367                  shares_name                  shares:hostID
368                  files_shareID                  shares:name
369                  files_path                  files:shareID
370                  files_name                  files:path
371                  files_date                  files:name
372                  files_size                  files:date
373                    files:size
374                    archive:dvd_nr
375                    archive_burned:archive_id
376                    backup_parts:backup_id,part_nr
377          )) {          )) {
                 print " $index";  
378                  do_index($index);                  do_index($index);
379          }          }
380    
381            print " creating sequence: ";
382            foreach my $seq (qw/dvd_nr/) {
383                    print "$seq ";
384                    $dbh->do( qq{ CREATE SEQUENCE $seq } );
385            }
386    
387    
388          print "...\n";          print "...\n";
389    
390          $dbh->commit;          $dbh->commit;
# Line 487  WHERE hostID=? AND num=? AND shareid=? Line 428  WHERE hostID=? AND num=? AND shareid=?
428    
429  $sth->{insert_backups} = $dbh->prepare(qq{  $sth->{insert_backups} = $dbh->prepare(qq{
430  INSERT INTO backups (hostID, num, date, type, shareid, size)  INSERT INTO backups (hostID, num, date, type, shareid, size)
431  VALUES (?,?,?,?,?,?)  VALUES (?,?,?,?,?,-1)
432    });
433    
434    $sth->{update_backups_size} = $dbh->prepare(qq{
435    UPDATE backups SET size = ?
436    WHERE hostID = ? and num = ? and date = ? and type =? and shareid = ?
437  });  });
438    
439  $sth->{insert_files} = $dbh->prepare(qq{  $sth->{insert_files} = $dbh->prepare(qq{
# Line 496  INSERT INTO files Line 442  INSERT INTO files
442          VALUES (?,?,?,?,?,?,?)          VALUES (?,?,?,?,?,?,?)
443  });  });
444    
445  foreach my $host_key (keys %{$hosts}) {  my @hosts = keys %{$hosts};
446    my $host_nr = 0;
447    
448    foreach my $host_key (@hosts) {
449    
450          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";
451    
# Line 511  foreach my $host_key (keys %{$hosts}) { Line 460  foreach my $host_key (keys %{$hosts}) {
460                  $hostID = $dbh->last_insert_id(undef,undef,'hosts',undef);                  $hostID = $dbh->last_insert_id(undef,undef,'hosts',undef);
461          }          }
462    
463          print "host ".$hosts->{$host_key}->{'host'}.": ";          $host_nr++;
   
464          # get backups for a host          # get backups for a host
465          my @backups = $bpc->BackupInfoRead($hostname);          my @backups = $bpc->BackupInfoRead($hostname);
466          my $incs = scalar @backups;          my $incs = scalar @backups;
         print  "$incs increments\n";  
467    
468            my $host_header = sprintf("host %s [%d/%d]: %d increments\n",
469                    $hosts->{$host_key}->{'host'},
470                    $host_nr,
471                    ($#hosts + 1),
472                    $incs
473            );
474            print $host_header unless ($opt{q});
475    
476          my $inc_nr = 0;          my $inc_nr = 0;
477          $beenThere = {};          $beenThere = {};
478    
# Line 529  foreach my $host_key (keys %{$hosts}) { Line 484  foreach my $host_key (keys %{$hosts}) {
484                  my $backupNum = $backup->{'num'};                  my $backupNum = $backup->{'num'};
485                  my @backupShares = ();                  my @backupShares = ();
486    
487                  printf("%-10s %2d/%-2d #%-2d %s %5s/%5s files (date: %s dur: %s)\n",                  my $share_header = sprintf("%-10s %2d/%-2d #%-2d %s %5s/%5s files (date: %s dur: %s)\n",
488                          $hosts->{$host_key}->{'host'},                          $hosts->{$host_key}->{'host'},
489                          $inc_nr, $incs, $backupNum,                          $inc_nr, $incs, $backupNum,
490                          $backup->{type} || '?',                          $backup->{type} || '?',
# Line 537  foreach my $host_key (keys %{$hosts}) { Line 492  foreach my $host_key (keys %{$hosts}) {
492                          strftime($t_fmt,localtime($backup->{startTime})),                          strftime($t_fmt,localtime($backup->{startTime})),
493                          fmt_time($backup->{endTime} - $backup->{startTime})                          fmt_time($backup->{endTime} - $backup->{startTime})
494                  );                  );
495                    print $share_header unless ($opt{q});
496    
497                  my $files = BackupPC::View->new($bpc, $hostname, \@backups, 1);                  my $files = BackupPC::View->new($bpc, $hostname, \@backups, 1);
498                  foreach my $share ($files->shareList($backupNum)) {                  foreach my $share ($files->shareList($backupNum)) {
# Line 550  foreach my $host_key (keys %{$hosts}) { Line 506  foreach my $host_key (keys %{$hosts}) {
506                          # skip if allready in database!                          # skip if allready in database!
507                          next if ($count > 0);                          next if ($count > 0);
508    
509                            # dump host and share header for -q
510                            if ($opt{q}) {
511                                    if ($host_header) {
512                                            print $host_header;
513                                            $host_header = undef;
514                                    }
515                                    print $share_header;
516                            }
517    
518                          # dump some log                          # dump some log
519                          print curr_time," ", $share;                          print curr_time," ", $share;
520    
                         my ($f, $nf, $d, $nd, $size) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID);  
   
521                          $sth->{insert_backups}->execute(                          $sth->{insert_backups}->execute(
522                                  $hostID,                                  $hostID,
523                                  $backupNum,                                  $backupNum,
524                                  $backup->{'endTime'},                                  $backup->{'endTime'},
525                                  substr($backup->{'type'},0,4),                                  substr($backup->{'type'},0,4),
526                                  $shareID,                                  $shareID,
                                 $size,  
527                          );                          );
528    
529                          print " commit";                          my ($f, $nf, $d, $nd, $size) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID);
530                          $dbh->commit();  
531                            eval {
532                                    $sth->{update_backups_size}->execute(
533                                            $size,
534                                            $hostID,
535                                            $backupNum,
536                                            $backup->{'endTime'},
537                                            substr($backup->{'type'},0,4),
538                                            $shareID,
539                                    );
540                                    print " commit";
541                                    $dbh->commit();
542                            };
543                            if ($@) {
544                                    print " rollback";
545                                    $dbh->rollback();
546                            }
547    
548                          my $dur = (time() - $t) || 1;                          my $dur = (time() - $t) || 1;
549                          printf(" %d/%d files %d/%d dirs %0.2f MB [%.2f/s dur: %s]\n",                          printf(" %d/%d files %d/%d dirs %0.2f MB [%.2f/s dur: %s]\n",
# Line 604  sub getShareID() { Line 582  sub getShareID() {
582    
583          $sth->{insert_share} ||= $dbh->prepare(qq{          $sth->{insert_share} ||= $dbh->prepare(qq{
584                  INSERT INTO shares                  INSERT INTO shares
585                          (hostID,name,share,localpath)                          (hostID,name,share)
586                  VALUES (?,?,?,?)                  VALUES (?,?,?)
587          });          });
588    
589          my $drop_down = $hostname . '/' . $share;          my $drop_down = $hostname . '/' . $share;
590          $drop_down =~ s#//+#/#g;          $drop_down =~ s#//+#/#g;
591    
592          $sth->{insert_share}->execute($hostID,$share, $drop_down ,undef);          $sth->{insert_share}->execute($hostID,$share, $drop_down);
593          return $dbh->last_insert_id(undef,undef,'shares',undef);          return $dbh->last_insert_id(undef,undef,'shares',undef);
594  }  }
595    
# Line 628  sub found_in_db { Line 606  sub found_in_db {
606                  SELECT 1 FROM files                  SELECT 1 FROM files
607                  WHERE shareID = ? and                  WHERE shareID = ? and
608                          path = ? and                          path = ? and
609                          date = ? and                          size = ? and
610                          size = ?                          ( date = ? or date = ? or date = ? )
611                  LIMIT 1                  LIMIT 1
612          });          });
613    
614          my @param = ($shareID,$path,$date,$size);          my @param = ($shareID,$path,$size,$date, $date-$dst_offset, $date+$dst_offset);
615          $sth->{file_in_db}->execute(@param);          $sth->{file_in_db}->execute(@param);
616          my $rows = $sth->{file_in_db}->rows;          my $rows = $sth->{file_in_db}->rows;
617          print STDERR "## found_in_db($shareID,$path,$date,$size) ",( $rows ? '+' : '-' ), join(" ",@param), "\n" if ($debug >= 3);          print STDERR "## found_in_db($shareID,$path,$date,$size) ",( $rows ? '+' : '-' ), join(" ",@param), "\n" if ($debug >= 3);
# Line 683  sub recurseDir($$$$$$$$) { Line 661  sub recurseDir($$$$$$$$) {
661                                  $filesInBackup->{$path_key}->{'size'}                                  $filesInBackup->{$path_key}->{'size'}
662                          ));                          ));
663    
664                            my $key_dst_prev = join(" ", (
665                                    $shareID,
666                                    $dir,
667                                    $path_key,
668                                    $filesInBackup->{$path_key}->{'mtime'} - $dst_offset,
669                                    $filesInBackup->{$path_key}->{'size'}
670                            ));
671    
672                            my $key_dst_next = join(" ", (
673                                    $shareID,
674                                    $dir,
675                                    $path_key,
676                                    $filesInBackup->{$path_key}->{'mtime'} + $dst_offset,
677                                    $filesInBackup->{$path_key}->{'size'}
678                            ));
679    
680                          my $found;                          my $found;
681                          if (! defined($beenThere->{$key}) && ! ($found = found_in_db($key, @data)) ) {                          if (
682                                    ! defined($beenThere->{$key}) &&
683                                    ! defined($beenThere->{$key_dst_prev}) &&
684                                    ! defined($beenThere->{$key_dst_next}) &&
685                                    ! ($found = found_in_db($key, @data))
686                            ) {
687                                  print STDERR "# key: $key [", $beenThere->{$key},"]" if ($debug >= 2);                                  print STDERR "# key: $key [", $beenThere->{$key},"]" if ($debug >= 2);
688    
689                                  if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {                                  if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {

Legend:
Removed from v.136  
changed lines
  Added in v.315

  ViewVC Help
Powered by ViewVC 1.1.26