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

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

  ViewVC Help
Powered by ViewVC 1.1.26