/[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 6 by dpavlin, Thu Jun 23 09:47:59 2005 UTC revision 82 by dpavlin, Sun Aug 28 09:12:54 2005 UTC
# Line 1  Line 1 
1  #!/usr/local/bin/perl -w  #!/usr/local/bin/perl -w
 $| = 1;  
2    
3  use strict;  use strict;
 use DBI;  
4  use lib "__INSTALLDIR__/lib";  use lib "__INSTALLDIR__/lib";
5    
6    use DBI;
7  use BackupPC::Lib;  use BackupPC::Lib;
8  use BackupPC::View;  use BackupPC::View;
9  use Data::Dumper;  use Data::Dumper;
10  use Getopt::Std;  use Getopt::Std;
11    use Time::HiRes qw/time/;
12    use File::Pid;
13    use POSIX qw/strftime/;
14    
15  use constant BPC_FTYPE_DIR => 5;  use constant BPC_FTYPE_DIR => 5;
16    
17    my $debug = 0;
18    $|=1;
19    
20    my $start_t = time();
21    
22    my $pidfile = new File::Pid;
23    
24    if (my $pid = $pidfile->running ) {
25            die "$0 already running: $pid\n";
26    } elsif ($pidfile->pid ne $$) {
27            $pidfile->remove;
28            $pidfile = new File::Pid;
29    }
30    $pidfile->write;
31    print STDERR "$0 using pid ",$pidfile->pid," file ",$pidfile->file,"\n";
32    
33    my $t_fmt = '%Y-%m-%d %H:%M:%S';
34    
35  my $hosts;  my $hosts;
36  my $bpc = BackupPC::Lib->new || die;  my $bpc = BackupPC::Lib->new || die;
37  my %Conf = $bpc->Conf();  my %Conf = $bpc->Conf();
38  my $TopDir = $bpc->TopDir();  my $TopDir = $bpc->TopDir();
39  my @beenThere = ();  my $beenThere = {};
40    
41  print Dumper(\%Conf);  my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n";
42    my $user = $Conf{SearchUser} || '';
43    my $index_path = $Conf{HyperEstraierIndex};
44    
45  my $dbh = DBI->connect("dbi:SQLite:dbname=$TopDir/$Conf{SearchDB}", "", "", { RaiseError => 1, AutoCommit => 0 });  my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 });
46    
47  my %opt;  my %opt;
48    
49  if ( !getopts("cdu", \%opt ) ) {  if ( !getopts("cdm:v:i", \%opt ) ) {
50          print STDERR <<EOF;          print STDERR <<EOF;
51  usage: $0 (-c|-df|-u)  usage: $0 [-c|-d] [-m num] [-v|-v level] [-i]
52    
53  Options:  Options:
54          -c      Create database on first use          -c      create database on first use
55          -d      Delete database before import          -d      delete database before import
56          -u      Update database (import new revisions)          -m num  import just num increments for one host
57            -v num  set verbosity (debug) level (default $debug)
58            -i      update HyperEstraier full text index
59  EOF  EOF
60          exit 1;          exit 1;
61  }  }
62    
63    if ($opt{v}) {
64            print "Debug level at $opt{v}\n";
65            $debug = $opt{v};
66    }
67    
68    ## update index ##
69    if ($opt{i}) {
70    
71            print "updating HyperEstraier files ";
72            
73            my $sth = $dbh->prepare(qq{
74                    SELECT
75                            files.id                        AS fid,
76                            hosts.name                      AS hname,
77                            shares.name                     AS sname,
78                            shares.share                    AS sharename,
79                            files.backupNum                 AS backupNum,
80                            files.name                      AS filename,
81                            files.path                      AS filepath,
82                            files.date                      AS date,
83                            files.type                      AS filetype,
84                            files.size                      AS size,
85                            files.shareid                   AS shareid
86                    FROM files
87                            INNER JOIN shares       ON files.shareID=shares.ID
88                            INNER JOIN hosts        ON hosts.ID = shares.hostID
89                            INNER JOIN backups      ON backups.num = files.backupNum and backups.hostID = hosts.ID AND backups.shareID = shares.ID
90            });
91    
92            $sth->execute();
93    
94            my $dot = int($sth->rows / 15);
95    
96            print $sth->rows, " files ($dot/#) ";
97    
98            sub fmt_date {
99                    my $t = shift || return;
100                    my $iso = BackupPC::Lib::timeStamp($t);
101                    $iso =~ s/\s/T/;
102                    return $iso;
103            }
104    
105            my $i = 0;
106            my $max = int($sth->rows / $dot);
107    
108            $index_path = $TopDir . '/' . $index_path;
109            $index_path =~ s#//#/#g;
110    
111            print "index $index_path...";
112            use HyperEstraier;
113            my $db = HyperEstraier::Database->new();
114            $db->open($index_path, $HyperEstraier::Database::DBWRITER | $HyperEstraier::Database::DBCREAT);
115    
116    
117            while (my $row = $sth->fetchrow_hashref()) {
118    
119                    # create a document object
120                    my $doc = HyperEstraier::Document->new;
121    
122                    # add attributes to the document object
123                    $doc->add_attr('@uri', 'file:///' . $row->{'fid'});
124    
125                    foreach my $c (qw/fid hname sname sharename backupNum filename filepath shareid/) {
126                            $doc->add_attr($c, $row->{$c}) if ($row->{$c});
127                    }
128    
129                    $doc->add_attr('date', fmt_date($row->{'date'}));
130    
131                    # add the body text to the document object
132                    my $path = $row->{'filepath'};
133                    $doc->add_text($path);
134                    $path =~ s/(.)/$1 /g;
135                    $doc->add_hidden_text($path);
136    
137                    print STDERR $doc->dump_draft,"\n" if ($debug > 1);
138    
139                    # register the document object to the database
140                    $db->put_doc($doc, $HyperEstraier::Database::PDCLEAN);
141    
142                    $i++;
143                    if ($i % $dot == 0) {
144                            print "$max ";
145                            $max--;
146                    }
147    
148            }
149    
150            print "sync";
151            $db->sync();
152            print " close\n";
153            $db->close();
154    
155            exit;
156    }
157    
158  ###################################create tables############################3  ###################################create tables############################3
159    
160  if ($opt{c})  if ($opt{c}) {
161      {          sub do_index {
162        print "creating database...";                  my $index = shift || return;
163                    my ($table,$col,$unique) = split(/_/, $index);
164                    $unique ||= '';
165                    $index =~ s/,/_/g;
166                    $dbh->do(qq{ create $unique index $index on $table($col) });
167            }
168    
169            print "creating tables...\n";
170                
171        $dbh->do(          $dbh->do(qq{
172            q{                  create table hosts (
173                create table hosts                          ID      SERIAL          PRIMARY KEY,
174                  (   ID             INTEGER              PRIMARY KEY,                          name    VARCHAR(30)     NOT NULL,
175                      name             VARCHAR(30)        NOT NULL,                          IP      VARCHAR(15)
                     IP       VARCHAR(20)        NOT NULL  
176                  );                              );            
177            }          });
       );  
178                                
179        $dbh->do(          $dbh->do(qq{
180            q{                  create table shares (
181                create table shares                          ID      SERIAL          PRIMARY KEY,
182                  (   ID             INTEGER           PRIMARY KEY,                          hostID  INTEGER         NOT NULL references hosts(id),
183                      hostID         INTEGER           NOT NULL,                          name    VARCHAR(30)     NOT NULL,
184                      name           VARCHAR(30)       NOT NULL,                          share   VARCHAR(200)    NOT NULL,
185                      share          VARCHAR(200)      NOT NULL,                          localpath VARCHAR(200)      
                     localpath      VARCHAR(200)        
186                  );                              );            
187            }          });
       );  
188                    
189        $dbh->do(          $dbh->do(qq{
190            q{                  create table backups (
191                create table backups                          hostID  INTEGER         NOT NULL references hosts(id),
192                  ( hostID     INTEGER            NOT NULL,                          num     INTEGER         NOT NULL,
193                      num      INTEGER            NOT NULL,                          date    integer         NOT NULL,
194                      date             DATE,                          type    CHAR(4)         not null,
195                      type             CHAR(1),                          shareID integer         not null references shares(id),
196                      PRIMARY KEY(hostID, num)                          size    integer         not null,
197                            PRIMARY KEY(hostID, num, shareID)
198                  );                              );            
199            }          });
200        );  
201            #do_index('backups_hostid,num_unique');
202    
203        $dbh->do(          $dbh->do(qq{
204            q{                  create table dvds (
205                create table dvds                          ID      SERIAL          PRIMARY KEY,
206                  ( ID         INTEGER            PRIMARY KEY,                          num     INTEGER         NOT NULL,
207                      num      INTEGER            NOT NULL,                          name    VARCHAR(255)    NOT NULL,
208                      name             VARCHAR(255)       NOT NULL,                          mjesto  VARCHAR(255)
                     mjesto     VARCHAR(255)  
209                  );                  );
210            }          });
       );  
211    
212        $dbh->do(          $dbh->do(qq{    
213            q{                      create table files (
214                create table files                          ID      SERIAL          PRIMARY KEY,  
215                  (   ID         INTEGER          NOT NULL PRIMARY KEY,                            shareID INTEGER         NOT NULL references shares(id),
216                      shareID    INTEGER          NOT NULL,                          backupNum  INTEGER      NOT NULL,
217                      backupNum  INTEGER          NOT NULL,                          name       VARCHAR(255) NOT NULL,
218                      name       VARCHAR(255)     NOT NULL,                          path       VARCHAR(255) NOT NULL,
219                      path       VARCHAR(255)     NOT NULL,                          date       integer      NOT NULL,
220                      fullpath   VARCHAR(255)     NOT NULL,                          type       INTEGER      NOT NULL,
221                      date       TIMESTAMP        NOT NULL,                          size       INTEGER      NOT NULL,
222                      type       INTEGER          NOT NULL,                          dvdid      INTEGER      references dvds(id)    
                     size       INTEGER          NOT NULL,  
                     dvdid      INTEGER            
223                  );                  );
224            }          });
225        );  
226        print "done\n";          print "creating indexes:";
227    }  
228            foreach my $index (qw(
229  if ($opt{d})                  hosts_name
230    {                  backups_hostID
231        print("deleting db first...\n");                  backups_num
232                          shares_hostID
233        $dbh->do(                  shares_name
234            q{ DELETE FROM hosts; }                  files_shareID
235            );                  files_path
236        $dbh->do(                  files_name
237            q{ DELETE FROM shares; }                  files_date
238            );                  files_size
239        $dbh->do(          )) {
240            q{ DELETE FROM files;}                  print " $index";
241            );                  do_index($index);
242        $dbh->do(          }
243            q{ DELETE FROM dvds;}          print "...\n";
244            );  
245        $dbh->do(          $dbh->commit;
246            q{ DELETE FROM backups; }  
247            );  }
248    }  
249    if ($opt{d}) {
250            print "deleting ";
251            foreach my $table (qw(files dvds backups shares hosts)) {
252                    print "$table ";
253                    $dbh->do(qq{ DELETE FROM $table });
254            }
255            print " done...\n";
256    
257            $dbh->commit;
258    }
259    
260  #################################INSERT VALUES#############################  #################################INSERT VALUES#############################
261    
262  # get hosts  # get hosts
263  $hosts = $bpc->HostInfoRead("localhost");  $hosts = $bpc->HostInfoRead();
 my $host_key;  
264  my $hostID;  my $hostID;
265  my $shareID;  my $shareID;
266  foreach $host_key (keys %{$hosts})  
267  {  my $sth;
268    my $hostname = $hosts->{$host_key}->{'host'};  
269    my $backups;  $sth->{insert_hosts} = $dbh->prepare(qq{
270    my $sql;  INSERT INTO hosts (name, IP) VALUES (?,?)
271    });
272    $sql = q{ SELECT ID FROM hosts WHERE name=? };  
273    my $st = $dbh->prepare($sql);  $sth->{hosts_by_name} = $dbh->prepare(qq{
274    $st->bind_param(1,$hosts->{$host_key}->{'host'});  SELECT ID FROM hosts WHERE name=?
275    $st->execute();  });
276    my $tmp = $st->fetchrow_hashref();  
277    if ($tmp->{'ID'} ne "")  $sth->{backups_count} = $dbh->prepare(qq{
278        {  SELECT COUNT(*)
279            $hostID = $tmp->{'ID'};  FROM backups
280        }  WHERE hostID=? AND num=? AND shareid=?
281      else  });
282        {  
283            $sql = q{ INSERT INTO hosts ( ID, name, IP) VALUES (NULL,"}.  $sth->{insert_backups} = $dbh->prepare(qq{
284                      $hosts->{$host_key}->{'host'}."\", \"".  INSERT INTO backups (hostID, num, date, type, shareid, size)
285                     $hosts->{$host_key}->{'ip'}."\");";  VALUES (?,?,?,?,?,?)
286    });
287            $dbh->do($sql);  
288            $hostID = $dbh->func('last_insert_rowid');  $sth->{insert_files} = $dbh->prepare(qq{
289    INSERT INTO files
290        }          (shareID, backupNum, name, path, date, type, size)
291    $st->finish();          VALUES (?,?,?,?,?,?,?)
292    print("processing host ".$hosts->{$host_key}->{'host'}.":\n");  });
293    
294    sub fmt_time {
295            my $t = shift || return;
296            my $out = "";
297            my ($ss,$mm,$hh) = gmtime($t);
298            $out .= "${hh}h" if ($hh);
299            $out .= sprintf("%02d:%02d", $mm,$ss);
300            return $out;
301    }
302    
303    foreach my $host_key (keys %{$hosts}) {
304    
305            my $hostname = $hosts->{$host_key}->{'host'} || die "can't find host for $host_key";
306    
307            $sth->{hosts_by_name}->execute($hosts->{$host_key}->{'host'});
308    
309            unless (($hostID) = $sth->{hosts_by_name}->fetchrow_array()) {
310                    $sth->{insert_hosts}->execute(
311                            $hosts->{$host_key}->{'host'},
312                            $hosts->{$host_key}->{'ip'}
313                    );
314    
315                    $hostID = $dbh->last_insert_id(undef,undef,'hosts',undef);
316            }
317    
318            print "host ".$hosts->{$host_key}->{'host'}.": ";
319    
320    # get backups for a host          # get backups for a host
321    my @backups = $bpc->BackupInfoRead($hostname);          my @backups = $bpc->BackupInfoRead($hostname);
322    foreach my $backup (@backups)          my $incs = scalar @backups;
323    {          print  "$incs increments\n";
324      my $backupNum = $backup->{'num'};  
325      my @backupShares = ();          my $inc_nr = 0;
326            $beenThere = {};
327    
328            foreach my $backup (@backups) {
329    
330                    $inc_nr++;
331                    last if ($opt{m} && $inc_nr > $opt{m});
332    
333                    my $backupNum = $backup->{'num'};
334                    my @backupShares = ();
335    
336                    printf("%-10s %2d/%-2d #%-2d %s %5s/%5s files (date: %s dur: %s)\n",
337                            $hosts->{$host_key}->{'host'},
338                            $inc_nr, $incs, $backupNum,
339                            $backup->{type} || '?',
340                            $backup->{nFilesNew} || '?', $backup->{nFiles} || '?',
341                            strftime($t_fmt,localtime($backup->{startTime})),
342                            fmt_time($backup->{endTime} - $backup->{startTime})
343                    );
344    
345                    my $files = BackupPC::View->new($bpc, $hostname, \@backups, 1);
346                    foreach my $share ($files->shareList($backupNum)) {
347    
348                            my $t = time();
349    
350                            $shareID = getShareID($share, $hostID, $hostname);
351                    
352                            $sth->{backups_count}->execute($hostID, $backupNum, $shareID);
353                            my ($count) = $sth->{backups_count}->fetchrow_array();
354                            # skip if allready in database!
355                            next if ($count > 0);
356    
357                            # dump some log
358                            print strftime($t_fmt,localtime())," ", $share;
359    
360                            my ($f, $nf, $d, $nd, $size) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID);
361    
362                            $sth->{insert_backups}->execute(
363                                    $hostID,
364                                    $backupNum,
365                                    $backup->{'endTime'},
366                                    $backup->{'type'},
367                                    $shareID,
368                                    $size,
369                            );
370    
371                            print " commit";
372                            $dbh->commit();
373    
374                            my $dur = (time() - $t) || 1;
375                            printf(" %d/%d files %d/%d dirs %0.2f MB [%.2f/s dur: %s]\n",
376                                    $nf, $f, $nd, $d,
377                                    ($size / 1024 / 1024),
378                                    ( ($f+$d) / $dur ),
379                                    fmt_time($dur)
380                            );
381                    }
382    
         
     if ($opt{u})  
         {  
             my $sql = q{  
                   SELECT COUNT(*) AS broj  
                   FROM backups  
                   WHERE hostID=? AND  
                         num=?  
                 };  
               
             my $st  = $dbh->prepare($sql);  
             $st->bind_param(1,$hostID);  
             $st->bind_param(2,$backupNum);  
             $st->execute();  
             my $tmp = $st->fetchrow_hashref();  
             $st->finish();  
             if ($tmp->{'broj'} > 0)  
               {  
                   next;  
               }  
383          }          }
         
     print "\tprocessing backup no. $backupNum...";  
     my $sql =      
         q{  
             INSERT INTO backups (hostID, num, date, type)  
               VALUES  
               (}.$hostID.",". $backupNum.q{, }.$backup->{'endTime'}.",\"". $backup->{'type'}.q{");  
          };  
     $dbh->do($sql);  
   
     my $files = BackupPC::View->new($bpc, $hostname, \@backups);  
     @backupShares = $files->shareList($backupNum);  
     foreach my $share (@backupShares)  
     {        
       my @flattenedFiles = ();  
       clearBeenThereCache();  
       print "\n\t\tprocessing share ".$share."...";  
       $shareID = getShareID($share, $hostID, $hostname);  
           
       @flattenedFiles = recurseDir($bpc, $hostname, \@backups, $backupNum, $share, "");  
       print "done\n";  
       print "\t\tinserting data into db...";  
       foreach my $file (@flattenedFiles)  
           {  
               $dbh->do("INSERT INTO files(ID, shareID, backupNum, name, path, fullpath, date, type, size) VALUES "  
                   ."( NULL, $shareID, "  
                   .$backupNum.", \""  
                   .$file->{'fileName'}."\", \""  
                   .$file->{'relPath'}. "\", \""  
                   .$file->{'fullPath'}."\", "  
                   .$file->{'mtime'}.", "  
                   .$file->{'type'}.", "  
                   .$file->{'size'}.")"  
                   );  
           }  
       print "done\n";  
     }  
   }  
   print "done.\n";  
384  }  }
385    undef $sth;
386  $dbh->commit();  $dbh->commit();
387  $dbh->disconnect();  $dbh->disconnect();
388    
389    print "total duration: ",fmt_time(time() - $start_t),"\n";
390    
391  sub haveBeenThere  $pidfile->remove;
392  {  
393    my ($where) = @_;  sub getShareID() {
394      
395    foreach my $st (@beenThere)          my ($share, $hostID, $hostname) = @_;
396    {  
397      if ($where eq $st)          $sth->{share_id} ||= $dbh->prepare(qq{
398      {                  SELECT ID FROM shares WHERE hostID=? AND name=?
399        return 1;          });
400      }  
401    }          $sth->{share_id}->execute($hostID,$share);
402      
403    push(@beenThere, $where);          my ($id) = $sth->{share_id}->fetchrow_array();
404    return 0;  
405  }          return $id if (defined($id));
406    
407  sub clearBeenThereCache          $sth->{insert_share} ||= $dbh->prepare(qq{
408  {                  INSERT INTO shares
409    @beenThere = ();                          (hostID,name,share,localpath)
410  }                  VALUES (?,?,?,?)
411            });
412  sub getShareID()  
413    {          my $drop_down = $hostname . '/' . $share;
414        my ($share, $hostID, $hostname) = @_;          $drop_down =~ s#//+#/#g;
415        my $tmp;  
416                  $sth->{insert_share}->execute($hostID,$share, $drop_down ,undef);
417        my $st = $dbh -> prepare(" SELECT shares.ID AS ID FROM shares WHERE hostID=? AND name=?");          return $dbh->last_insert_id(undef,undef,'shares',undef);
418        $st -> execute($hostID,$share);  }
419        my $tmp = $st->fetchrow_hashref();  
420        $st->finish();  sub found_in_db {
421        if ($tmp)  
422          {          my @data = @_;
423              return $tmp->{'ID'};          shift @data;
424          }  
425        my $sql =          my ($key, $shareID,undef,$name,$path,$date,undef,$size) = @_;
426            q{  
427                INSERT INTO shares(ID,hostID,name,share,localpath)          return $beenThere->{$key} if (defined($beenThere->{$key}));
428                  VALUES    
429                 (NULL,}.                            $sth->{file_in_db} ||= $dbh->prepare(qq{
430                "$hostID,\"$share\",\"//$hostname$share\",NULL);";                                SELECT 1 FROM files
431        $dbh->do($sql);                  WHERE shareID = ? and
432        return $dbh->func('last_insert_rowid');                                    path = ? and
433    }                          date = ? and
434                            size = ?
435                    LIMIT 1
436            });
437    
438            my @param = ($shareID,$path,$date,$size);
439            $sth->{file_in_db}->execute(@param);
440            my $rows = $sth->{file_in_db}->rows;
441            print STDERR "## found_in_db($shareID,$path,$date,$size) ",( $rows ? '+' : '-' ), join(" ",@param), "\n" if ($debug >= 3);
442    
443            $beenThere->{$key}++;
444    
445            $sth->{'insert_files'}->execute(@data) unless ($rows);
446            return $rows;
447    }
448    
449  ####################################################  ####################################################
450  # recursing through filesystem structure and       #  # recursing through filesystem structure and       #
451  # and returning flattened files list               #  # and returning flattened files list               #
452  ####################################################  ####################################################
453  sub recurseDir  sub recurseDir($$$$$$$$) {
 {  
   my ($bpc, $hostname, $backups, $backupNo, $share, $dir) = @_;  
   my @ret = ();  
   my $files = BackupPC::View->new($bpc, $hostname, $backups);              
   my $filesInBackup = $files->dirAttrib($backupNo, $share, $dir);  
   my $file_key = "";  
454    
455            my ($bpc, $hostname, $files, $backupNum, $share, $dir, $shareID) = @_;
456    # first, add all the entries in current directory  
457    foreach $file_key (keys %{$filesInBackup})          print STDERR "\nrecurse($hostname,$backupNum,$share,$dir,$shareID)\n" if ($debug >= 1);
458    {  
459      push(@ret, {          my ($nr_files, $new_files, $nr_dirs, $new_dirs, $size) = (0,0,0,0,0);
460                   'fileName' => $file_key,  
461                   'relPath'  => $filesInBackup->{$file_key}->{'relPath'},          { # scope
462                   'fullPath' => $filesInBackup->{$file_key}->{'fullPath'},                  my @stack;
463                   'sharePath'=> $filesInBackup->{$file_key}->{'sharePathM'},  
464                   'size'     => $filesInBackup->{$file_key}->{'size'},                  print STDERR "# dirAttrib($backupNum, $share, $dir)\n" if ($debug >= 2);
465                   'mtime'    => $filesInBackup->{$file_key}->{'mtime'},                  my $filesInBackup = $files->dirAttrib($backupNum, $share, $dir);
466                   'type'     => $filesInBackup->{$file_key}->{'type'}  
467                 });                    # first, add all the entries in current directory
468    }                  foreach my $path_key (keys %{$filesInBackup}) {
469                                print STDERR "# file ",Dumper($filesInBackup->{$path_key}),"\n" if ($debug >= 3);
470    # then, recurse thru subfolders                          my @data = (
471    foreach my $fold (@ret)                                  $shareID,
472    {                                  $backupNum,
473     if ($fold->{'type'} == BPC_FTYPE_DIR &&                                  $path_key,
474         haveBeenThere($fold->{'relPath'}) != 1                                  $filesInBackup->{$path_key}->{'relPath'},
475        )                                  $filesInBackup->{$path_key}->{'mtime'},
476      {                                  $filesInBackup->{$path_key}->{'type'},
477                                          $filesInBackup->{$path_key}->{'size'}
478        push(@ret,                          );
479             recurseDir($bpc, $hostname, $backups, $backupNo, $share, $fold->{'relPath'})  
480            );                          my $key = join(" ", (
481      }                                  $shareID,
482    }                                  $dir,
483    return @ret;                                  $path_key,
484                                    $filesInBackup->{$path_key}->{'mtime'},
485                                    $filesInBackup->{$path_key}->{'size'}
486                            ));
487    
488                            my $found;
489                            if (! defined($beenThere->{$key}) && ! ($found = found_in_db($key, @data)) ) {
490                                    print STDERR "# key: $key [", $beenThere->{$key},"]" if ($debug >= 2);
491    
492                                    if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {
493                                            $new_dirs++ unless ($found);
494                                            print STDERR " dir\n" if ($debug >= 2);
495                                    } else {
496                                            $new_files++ unless ($found);
497                                            print STDERR " file\n" if ($debug >= 2);
498                                    }
499                                    $size += $filesInBackup->{$path_key}->{'size'} || 0;
500                            }
501    
502                            if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {
503                                    $nr_dirs++;
504    
505                                    my $full_path = $dir . '/' . $path_key;
506                                    push @stack, $full_path;
507                                    print STDERR "### store to stack: $full_path\n" if ($debug >= 3);
508    
509    #                               my ($f,$nf,$d,$nd) = recurseDir($bpc, $hostname, $backups, $backupNum, $share, $path_key, $shareID) unless ($beenThere->{$key});
510    #
511    #                               $nr_files += $f;
512    #                               $new_files += $nf;
513    #                               $nr_dirs += $d;
514    #                               $new_dirs += $nd;
515    
516                            } else {
517                                    $nr_files++;
518                            }
519                    }
520    
521                    print STDERR "## STACK ",join(", ", @stack),"\n" if ($debug >= 2);
522    
523                    while ( my $dir = shift @stack ) {
524                            my ($f,$nf,$d,$nd, $s) = recurseDir($bpc, $hostname, $files, $backupNum, $share, $dir, $shareID);
525                            print STDERR "# $dir f: $f nf: $nf d: $d nd: $nd\n" if ($debug >= 1);
526                            $nr_files += $f;
527                            $new_files += $nf;
528                            $nr_dirs += $d;
529                            $new_dirs += $nd;
530                            $size += $s;
531                    }
532            }
533    
534            return ($nr_files, $new_files, $nr_dirs, $new_dirs, $size);
535  }  }
536    

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

  ViewVC Help
Powered by ViewVC 1.1.26