/[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 30 by dpavlin, Sun Jul 31 15:59:19 2005 UTC revision 37 by dpavlin, Fri Aug 19 14:57:30 2005 UTC
# Line 7  use BackupPC::Lib; Line 7  use BackupPC::Lib;
7  use BackupPC::View;  use BackupPC::View;
8  use Data::Dumper;  use Data::Dumper;
9  use Getopt::Std;  use Getopt::Std;
10    use Time::HiRes qw/time/;
11    use POSIX qw/strftime/;
12  use constant BPC_FTYPE_DIR => 5;  use constant BPC_FTYPE_DIR => 5;
13    
14  my $debug = 0;  my $debug = 0;
15  $|=1;  $|=1;
16    
17    my $t_fmt = '%Y-%m-%d %H:%M:%S';
18    
19  my $hosts;  my $hosts;
20  my $bpc = BackupPC::Lib->new || die;  my $bpc = BackupPC::Lib->new || die;
21  my %Conf = $bpc->Conf();  my %Conf = $bpc->Conf();
# Line 24  my $dbh = DBI->connect($dsn, "", "", { R Line 28  my $dbh = DBI->connect($dsn, "", "", { R
28    
29  my %opt;  my %opt;
30    
31  if ( !getopts("cdm:", \%opt ) ) {  if ( !getopts("cdm:v", \%opt ) ) {
32          print STDERR <<EOF;          print STDERR <<EOF;
33  usage: $0 [-c|-d] [-m num]  usage: $0 [-c|-d] [-m num]
34    
# Line 123  if ($opt{d}) { Line 127  if ($opt{d}) {
127          print " done...\n";          print " done...\n";
128  }  }
129    
130    if ($opt{v}) {
131            print "Debug level at $opt{v}\n";
132            $debug = $opt{v};
133    }
134    
135  #################################INSERT VALUES#############################  #################################INSERT VALUES#############################
136    
137  # get hosts  # get hosts
# Line 187  foreach my $host_key (keys %{$hosts}) { Line 196  foreach my $host_key (keys %{$hosts}) {
196                  my $backupNum = $backup->{'num'};                  my $backupNum = $backup->{'num'};
197                  my @backupShares = ();                  my @backupShares = ();
198    
199                  print $hosts->{$host_key}->{'host'},"\t#$backupNum\n";                  print $hosts->{$host_key}->{'host'}, "\t#$backupNum\n";
200    
201                  $sth->{backups_broj}->execute($hostID, $backupNum);                  $sth->{backups_broj}->execute($hostID, $backupNum);
202                  my ($broj) = $sth->{backups_broj}->fetchrow_array();                  my ($broj) = $sth->{backups_broj}->fetchrow_array();
203                  next if ($broj > 0);                  next if ($broj > 0);
204    
205                  my $files = BackupPC::View->new($bpc, $hostname, \@backups);                  my $files = BackupPC::View->new($bpc, $hostname, \@backups, 1);
206                  foreach my $share ($files->shareList($backupNum)) {                  foreach my $share ($files->shareList($backupNum)) {
207    
208                          print "\t$share";                          my $t = time();
209    
210                            print strftime($t_fmt,localtime())," ", $share;
211                          $shareID = getShareID($share, $hostID, $hostname);                          $shareID = getShareID($share, $hostID, $hostname);
212                                    
213                          my ($f, $nf, $d, $nd) = recurseDir($bpc, $hostname, \@backups, $backupNum, $share, "", $shareID);                          my ($f, $nf, $d, $nd) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID);
214                          print " $nf/$f files $nd/$d dirs\n";                          printf(" %d/%d files %d/%d dirs [%.2f/s]\n",
215                                    $nf, $f, $nd, $d,
216                                    ( ($f+$d) / ((time() - $t) || 1) )
217                            );
218                          $dbh->commit();                          $dbh->commit();
219                  }                  }
220    
# Line 271  sub found_in_db { Line 285  sub found_in_db {
285  ####################################################  ####################################################
286  sub recurseDir($$$$$$$$) {  sub recurseDir($$$$$$$$) {
287    
288          my ($bpc, $hostname, $backups, $backupNum, $share, $dir, $shareID) = @_;          my ($bpc, $hostname, $files, $backupNum, $share, $dir, $shareID) = @_;
289    
290          print STDERR "recurse($hostname,$backupNum,$share,$dir,$shareID)\n" if ($debug >= 1);          print STDERR "recurse($hostname,$backupNum,$share,$dir,$shareID)\n" if ($debug >= 1);
291    
# Line 280  sub recurseDir($$$$$$$$) { Line 294  sub recurseDir($$$$$$$$) {
294          { # scope          { # scope
295                  my @stack;                  my @stack;
296    
                 my $files = BackupPC::View->new($bpc, $hostname, $backups);              
297                  my $filesInBackup = $files->dirAttrib($backupNum, $share, $dir);                  my $filesInBackup = $files->dirAttrib($backupNum, $share, $dir);
298    
299                  # first, add all the entries in current directory                  # first, add all the entries in current directory
# Line 341  sub recurseDir($$$$$$$$) { Line 354  sub recurseDir($$$$$$$$) {
354                  print STDERR "## STACK ",join(", ", @stack),"\n" if ($debug >= 2);                  print STDERR "## STACK ",join(", ", @stack),"\n" if ($debug >= 2);
355    
356                  while ( my $dir = shift @stack ) {                  while ( my $dir = shift @stack ) {
357                          my ($f,$nf,$d,$nd) = recurseDir($bpc, $hostname, $backups, $backupNum, $share, $dir, $shareID);                          my ($f,$nf,$d,$nd) = recurseDir($bpc, $hostname, $files, $backupNum, $share, $dir, $shareID);
358                          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);
359                          $nr_files += $f;                          $nr_files += $f;
360                          $new_files += $nf;                          $new_files += $nf;

Legend:
Removed from v.30  
changed lines
  Added in v.37

  ViewVC Help
Powered by ViewVC 1.1.26