/[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 62 by dpavlin, Sun Aug 21 15:59:55 2005 UTC revision 67 by dpavlin, Mon Aug 22 08:58:59 2005 UTC
# Line 95  if ($opt{c}) { Line 95  if ($opt{c}) {
95                          num     INTEGER         NOT NULL,                          num     INTEGER         NOT NULL,
96                          date    integer         NOT NULL,                          date    integer         NOT NULL,
97                          type    CHAR(4)         not null,                          type    CHAR(4)         not null,
98                          PRIMARY KEY(hostID, num)                          shareID integer         not null references shares(id),
99                            size    integer         not null,
100                            PRIMARY KEY(hostID, num, shareID)
101                  );                              );            
102          });          });
103    
104          do_index('backups_hostid,num_unique');          #do_index('backups_hostid,num_unique');
105    
106          $dbh->do(qq{          $dbh->do(qq{
107                  create table dvds (                  create table dvds (
# Line 180  $sth->{hosts_by_name} = $dbh->prepare(qq Line 182  $sth->{hosts_by_name} = $dbh->prepare(qq
182  SELECT ID FROM hosts WHERE name=?  SELECT ID FROM hosts WHERE name=?
183  });  });
184    
185  $sth->{backups_broj} = $dbh->prepare(qq{  $sth->{backups_count} = $dbh->prepare(qq{
186  SELECT COUNT(*)  SELECT COUNT(*)
187  FROM backups  FROM backups
188  WHERE hostID=? AND num=?  WHERE hostID=? AND num=? AND shareid=?
189  });  });
190    
191  $sth->{insert_backups} = $dbh->prepare(qq{  $sth->{insert_backups} = $dbh->prepare(qq{
192  INSERT INTO backups (hostID, num, date, type)  INSERT INTO backups (hostID, num, date, type, shareid, size)
193  VALUES (?,?,?,?)  VALUES (?,?,?,?,?,?)
194  });  });
195    
196  $sth->{insert_files} = $dbh->prepare(qq{  $sth->{insert_files} = $dbh->prepare(qq{
# Line 221  foreach my $host_key (keys %{$hosts}) { Line 223  foreach my $host_key (keys %{$hosts}) {
223                  $hostID = $dbh->last_insert_id(undef,undef,'hosts',undef);                  $hostID = $dbh->last_insert_id(undef,undef,'hosts',undef);
224          }          }
225    
226          print("host ".$hosts->{$host_key}->{'host'}.": ");          print "host ".$hosts->{$host_key}->{'host'}.": ";
227    
228          # get backups for a host          # get backups for a host
229          my @backups = $bpc->BackupInfoRead($hostname);          my @backups = $bpc->BackupInfoRead($hostname);
230          print scalar @backups, " increments\n";          my $incs = scalar @backups;
231            print  "$incs increments\n";
232    
233          my $inc_nr = 0;          my $inc_nr = 0;
234            $beenThere = {};
235    
236          foreach my $backup (@backups) {          foreach my $backup (@backups) {
237    
# Line 237  foreach my $host_key (keys %{$hosts}) { Line 241  foreach my $host_key (keys %{$hosts}) {
241                  my $backupNum = $backup->{'num'};                  my $backupNum = $backup->{'num'};
242                  my @backupShares = ();                  my @backupShares = ();
243    
244                  print $hosts->{$host_key}->{'host'},                  printf("%-10s %2d/%-2d #%-2d %s %5s/%5s files (date: %s dur: %s)\n",
245                          "\t#$backupNum\t", $backup->{type} || '?', " ",                          $hosts->{$host_key}->{'host'},
246                          $backup->{nFilesNew} || '?', "/", $backup->{nFiles} || '?',                          $inc_nr, $incs, $backupNum,
247                          " files (date: ",                          $backup->{type} || '?',
248                            $backup->{nFilesNew} || '?', $backup->{nFiles} || '?',
249                          strftime($t_fmt,localtime($backup->{startTime})),                          strftime($t_fmt,localtime($backup->{startTime})),
250                          " dur: ",                          fmt_time($backup->{endTime} - $backup->{startTime})
                         fmt_time($backup->{endTime} - $backup->{startTime}),  
                         ")\n";  
   
                 $sth->{backups_broj}->execute($hostID, $backupNum);  
                 my ($broj) = $sth->{backups_broj}->fetchrow_array();  
                 next if ($broj > 0);  
   
                 $sth->{insert_backups}->execute(  
                         $hostID,  
                         $backupNum,  
                         $backup->{'endTime'},  
                         $backup->{'type'}  
251                  );                  );
                 $dbh->commit();  
252    
253                  my $files = BackupPC::View->new($bpc, $hostname, \@backups, 1);                  my $files = BackupPC::View->new($bpc, $hostname, \@backups, 1);
254                  foreach my $share ($files->shareList($backupNum)) {                  foreach my $share ($files->shareList($backupNum)) {
255    
256                          my $t = time();                          my $t = time();
257    
                         print strftime($t_fmt,localtime())," ", $share;  
258                          $shareID = getShareID($share, $hostID, $hostname);                          $shareID = getShareID($share, $hostID, $hostname);
259                                    
260                          my ($f, $nf, $d, $nd) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID);                          $sth->{backups_count}->execute($hostID, $backupNum, $shareID);
261                            my ($count) = $sth->{backups_count}->fetchrow_array();
262                            # skip if allready in database!
263                            next if ($count > 0);
264    
265                            # dump some log
266                            print strftime($t_fmt,localtime())," ", $share;
267    
268                            my ($f, $nf, $d, $nd, $size) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID);
269    
270                            $sth->{insert_backups}->execute(
271                                    $hostID,
272                                    $backupNum,
273                                    $backup->{'endTime'},
274                                    $backup->{'type'},
275                                    $shareID,
276                                    $size,
277                            );
278    
279                            print " commit";
280                            $dbh->commit();
281    
282                          my $dur = (time() - $t) || 1;                          my $dur = (time() - $t) || 1;
283                          printf(" %d/%d files %d/%d dirs [%.2f/s dur: %s]\n",                          printf(" %d/%d files %d/%d dirs %0.2f MB [%.2f/s dur: %s]\n",
284                                  $nf, $f, $nd, $d,                                  $nf, $f, $nd, $d,
285                                    ($size / 1024 / 1024),
286                                  ( ($f+$d) / $dur ),                                  ( ($f+$d) / $dur ),
287                                  fmt_time($dur)                                  fmt_time($dur)
288                          );                          );
                         $dbh->commit();  
289                  }                  }
290    
291          }          }
# Line 326  sub found_in_db { Line 338  sub found_in_db {
338                  SELECT 1 FROM files                  SELECT 1 FROM files
339                  WHERE shareID = ? and                  WHERE shareID = ? and
340                          path = ? and                          path = ? and
                         name = ? and  
341                          date = ? and                          date = ? and
342                          size = ?                          size = ?
343          });          });
344    
345          my @param = ($shareID,$path,$name,$date,$size);          my @param = ($shareID,$path,$date,$size);
346          $sth->{file_in_db}->execute(@param);          $sth->{file_in_db}->execute(@param);
347          my $rows = $sth->{file_in_db}->rows;          my $rows = $sth->{file_in_db}->rows;
348          print STDERR "## found_in_db ",( $rows ? '+' : '-' ), join(" ",@param), "\n" if ($debug >= 3);          print STDERR "## found_in_db ",( $rows ? '+' : '-' ), join(" ",@param), "\n" if ($debug >= 3);
# Line 352  sub recurseDir($$$$$$$$) { Line 363  sub recurseDir($$$$$$$$) {
363    
364          print STDERR "\nrecurse($hostname,$backupNum,$share,$dir,$shareID)\n" if ($debug >= 1);          print STDERR "\nrecurse($hostname,$backupNum,$share,$dir,$shareID)\n" if ($debug >= 1);
365    
366          my ($nr_files, $new_files, $nr_dirs, $new_dirs) = (0,0,0,0);          my ($nr_files, $new_files, $nr_dirs, $new_dirs, $size) = (0,0,0,0,0);
367    
368          { # scope          { # scope
369                  my @stack;                  my @stack;
# Line 362  sub recurseDir($$$$$$$$) { Line 373  sub recurseDir($$$$$$$$) {
373    
374                  # first, add all the entries in current directory                  # first, add all the entries in current directory
375                  foreach my $path_key (keys %{$filesInBackup}) {                  foreach my $path_key (keys %{$filesInBackup}) {
376                            print STDERR "# file ",Dumper($filesInBackup->{$path_key}),"\n" if ($debug >= 3);
377                          my @data = (                          my @data = (
378                                  $shareID,                                  $shareID,
379                                  $backupNum,                                  $backupNum,
# Line 391  sub recurseDir($$$$$$$$) { Line 403  sub recurseDir($$$$$$$$) {
403                                          $new_files++;                                          $new_files++;
404                                          print STDERR " file\n" if ($debug >= 2);                                          print STDERR " file\n" if ($debug >= 2);
405                                  }                                  }
406                                    $size += $filesInBackup->{$path_key}->{'size'} || 0;
407                          }                          }
408    
409                          if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {                          if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {
# Line 415  sub recurseDir($$$$$$$$) { Line 428  sub recurseDir($$$$$$$$) {
428                  print STDERR "## STACK ",join(", ", @stack),"\n" if ($debug >= 2);                  print STDERR "## STACK ",join(", ", @stack),"\n" if ($debug >= 2);
429    
430                  while ( my $dir = shift @stack ) {                  while ( my $dir = shift @stack ) {
431                          my ($f,$nf,$d,$nd) = recurseDir($bpc, $hostname, $files, $backupNum, $share, $dir, $shareID);                          my ($f,$nf,$d,$nd, $s) = recurseDir($bpc, $hostname, $files, $backupNum, $share, $dir, $shareID);
432                          print STDERR "# $dir f: $f nf: $nf d: $d nd: $nd\n" if ($debug >= 1);                          print STDERR "# $dir f: $f nf: $nf d: $d nd: $nd\n" if ($debug >= 1);
433                          $nr_files += $f;                          $nr_files += $f;
434                          $new_files += $nf;                          $new_files += $nf;
435                          $nr_dirs += $d;                          $nr_dirs += $d;
436                          $new_dirs += $nd;                          $new_dirs += $nd;
437                            $size += $s;
438                  }                  }
439          }          }
440    
441          return ($nr_files, $new_files, $nr_dirs, $new_dirs);          return ($nr_files, $new_files, $nr_dirs, $new_dirs, $size);
442  }  }
443    

Legend:
Removed from v.62  
changed lines
  Added in v.67

  ViewVC Help
Powered by ViewVC 1.1.26