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 File::Pid; |
12 |
|
use POSIX qw/strftime/; |
13 |
use constant BPC_FTYPE_DIR => 5; |
use constant BPC_FTYPE_DIR => 5; |
14 |
|
|
15 |
my $debug = 0; |
my $debug = 0; |
16 |
$|=1; |
$|=1; |
17 |
|
|
18 |
|
my $pidfile = new File::Pid; |
19 |
|
|
20 |
|
if (my $pid = $pidfile->running ) { |
21 |
|
die "$0 already running: $pid\n"; |
22 |
|
} elsif ($pidfile->pid ne $$) { |
23 |
|
$pidfile->remove; |
24 |
|
$pidfile = new File::Pid; |
25 |
|
$pidfile->write; |
26 |
|
print STDERR "$0 using pid ",$pidfile->pid," file ",$pidfile->file,"\n"; |
27 |
|
} |
28 |
|
|
29 |
|
my $t_fmt = '%Y-%m-%d %H:%M:%S'; |
30 |
|
|
31 |
my $hosts; |
my $hosts; |
32 |
my $bpc = BackupPC::Lib->new || die; |
my $bpc = BackupPC::Lib->new || die; |
33 |
my %Conf = $bpc->Conf(); |
my %Conf = $bpc->Conf(); |
40 |
|
|
41 |
my %opt; |
my %opt; |
42 |
|
|
43 |
if ( !getopts("cdm:", \%opt ) ) { |
if ( !getopts("cdm:v", \%opt ) ) { |
44 |
print STDERR <<EOF; |
print STDERR <<EOF; |
45 |
usage: $0 [-c|-d] [-m num] |
usage: $0 [-c|-d] [-m num] |
46 |
|
|
139 |
print " done...\n"; |
print " done...\n"; |
140 |
} |
} |
141 |
|
|
142 |
|
if ($opt{v}) { |
143 |
|
print "Debug level at $opt{v}\n"; |
144 |
|
$debug = $opt{v}; |
145 |
|
} |
146 |
|
|
147 |
#################################INSERT VALUES############################# |
#################################INSERT VALUES############################# |
148 |
|
|
149 |
# get hosts |
# get hosts |
208 |
my $backupNum = $backup->{'num'}; |
my $backupNum = $backup->{'num'}; |
209 |
my @backupShares = (); |
my @backupShares = (); |
210 |
|
|
211 |
print $hosts->{$host_key}->{'host'},"\t#$backupNum\n"; |
print $hosts->{$host_key}->{'host'}, "\t#$backupNum\n"; |
212 |
|
|
213 |
$sth->{backups_broj}->execute($hostID, $backupNum); |
$sth->{backups_broj}->execute($hostID, $backupNum); |
214 |
my ($broj) = $sth->{backups_broj}->fetchrow_array(); |
my ($broj) = $sth->{backups_broj}->fetchrow_array(); |
215 |
next if ($broj > 0); |
next if ($broj > 0); |
216 |
|
|
217 |
my $files = BackupPC::View->new($bpc, $hostname, \@backups); |
my $files = BackupPC::View->new($bpc, $hostname, \@backups, 1); |
218 |
foreach my $share ($files->shareList($backupNum)) { |
foreach my $share ($files->shareList($backupNum)) { |
219 |
|
|
220 |
print "\t$share"; |
my $t = time(); |
221 |
|
|
222 |
|
print strftime($t_fmt,localtime())," ", $share; |
223 |
$shareID = getShareID($share, $hostID, $hostname); |
$shareID = getShareID($share, $hostID, $hostname); |
224 |
|
|
225 |
my ($f, $nf, $d, $nd) = recurseDir($bpc, $hostname, \@backups, $backupNum, $share, "", $shareID); |
my ($f, $nf, $d, $nd) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID); |
226 |
print " $nf/$f files $nd/$d dirs\n"; |
printf(" %d/%d files %d/%d dirs [%.2f/s]\n", |
227 |
|
$nf, $f, $nd, $d, |
228 |
|
( ($f+$d) / ((time() - $t) || 1) ) |
229 |
|
); |
230 |
$dbh->commit(); |
$dbh->commit(); |
231 |
} |
} |
232 |
|
|
244 |
$dbh->commit(); |
$dbh->commit(); |
245 |
$dbh->disconnect(); |
$dbh->disconnect(); |
246 |
|
|
247 |
|
$pidfile->remove; |
248 |
|
|
249 |
sub getShareID() { |
sub getShareID() { |
250 |
|
|
251 |
my ($share, $hostID, $hostname) = @_; |
my ($share, $hostID, $hostname) = @_; |
299 |
#################################################### |
#################################################### |
300 |
sub recurseDir($$$$$$$$) { |
sub recurseDir($$$$$$$$) { |
301 |
|
|
302 |
my ($bpc, $hostname, $backups, $backupNum, $share, $dir, $shareID) = @_; |
my ($bpc, $hostname, $files, $backupNum, $share, $dir, $shareID) = @_; |
303 |
|
|
304 |
print STDERR "recurse($hostname,$backupNum,$share,$dir,$shareID)\n" if ($debug >= 1); |
print STDERR "recurse($hostname,$backupNum,$share,$dir,$shareID)\n" if ($debug >= 1); |
305 |
|
|
308 |
{ # scope |
{ # scope |
309 |
my @stack; |
my @stack; |
310 |
|
|
|
my $files = BackupPC::View->new($bpc, $hostname, $backups); |
|
311 |
my $filesInBackup = $files->dirAttrib($backupNum, $share, $dir); |
my $filesInBackup = $files->dirAttrib($backupNum, $share, $dir); |
312 |
|
|
313 |
# first, add all the entries in current directory |
# first, add all the entries in current directory |
368 |
print STDERR "## STACK ",join(", ", @stack),"\n" if ($debug >= 2); |
print STDERR "## STACK ",join(", ", @stack),"\n" if ($debug >= 2); |
369 |
|
|
370 |
while ( my $dir = shift @stack ) { |
while ( my $dir = shift @stack ) { |
371 |
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); |
372 |
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); |
373 |
$nr_files += $f; |
$nr_files += $f; |
374 |
$new_files += $nf; |
$new_files += $nf; |