9 |
use Getopt::Std; |
use Getopt::Std; |
10 |
use constant BPC_FTYPE_DIR => 5; |
use constant BPC_FTYPE_DIR => 5; |
11 |
|
|
12 |
|
my $debug = 0; |
13 |
$|=1; |
$|=1; |
14 |
|
|
15 |
my $hosts; |
my $hosts; |
24 |
|
|
25 |
my %opt; |
my %opt; |
26 |
|
|
27 |
if ( !getopts("cdm:", \%opt ) ) { |
if ( !getopts("cdm:v", \%opt ) ) { |
28 |
print STDERR <<EOF; |
print STDERR <<EOF; |
29 |
usage: $0 [-c|-d] [-m num] |
usage: $0 [-c|-d] [-m num] |
30 |
|
|
123 |
print " done...\n"; |
print " done...\n"; |
124 |
} |
} |
125 |
|
|
126 |
|
if ($opt{v}) { |
127 |
|
print "Debug level at $opt{v}\n"; |
128 |
|
$debug = $opt{v}; |
129 |
|
} |
130 |
|
|
131 |
#################################INSERT VALUES############################# |
#################################INSERT VALUES############################# |
132 |
|
|
133 |
# get hosts |
# get hosts |
198 |
my ($broj) = $sth->{backups_broj}->fetchrow_array(); |
my ($broj) = $sth->{backups_broj}->fetchrow_array(); |
199 |
next if ($broj > 0); |
next if ($broj > 0); |
200 |
|
|
|
$sth->{insert_backups}->execute( |
|
|
$hostID, |
|
|
$backupNum, |
|
|
$backup->{'endTime'}, |
|
|
$backup->{'type'} |
|
|
); |
|
|
$dbh->commit(); |
|
|
|
|
201 |
my $files = BackupPC::View->new($bpc, $hostname, \@backups); |
my $files = BackupPC::View->new($bpc, $hostname, \@backups); |
202 |
foreach my $share ($files->shareList($backupNum)) { |
foreach my $share ($files->shareList($backupNum)) { |
203 |
|
|
208 |
print " $nf/$f files $nd/$d dirs\n"; |
print " $nf/$f files $nd/$d dirs\n"; |
209 |
$dbh->commit(); |
$dbh->commit(); |
210 |
} |
} |
211 |
|
|
212 |
|
$sth->{insert_backups}->execute( |
213 |
|
$hostID, |
214 |
|
$backupNum, |
215 |
|
$backup->{'endTime'}, |
216 |
|
$backup->{'type'} |
217 |
|
); |
218 |
|
$dbh->commit(); |
219 |
|
|
220 |
} |
} |
221 |
} |
} |
222 |
undef $sth; |
undef $sth; |
278 |
|
|
279 |
my ($bpc, $hostname, $backups, $backupNum, $share, $dir, $shareID) = @_; |
my ($bpc, $hostname, $backups, $backupNum, $share, $dir, $shareID) = @_; |
280 |
|
|
281 |
my ($nr_files, $new_files, $nr_dirs, $new_dirs) = (0,0,0,0); |
print STDERR "recurse($hostname,$backupNum,$share,$dir,$shareID)\n" if ($debug >= 1); |
282 |
|
|
283 |
my $files = BackupPC::View->new($bpc, $hostname, $backups); |
my ($nr_files, $new_files, $nr_dirs, $new_dirs) = (0,0,0,0); |
|
my $filesInBackup = $files->dirAttrib($backupNum, $share, $dir); |
|
284 |
|
|
285 |
# first, add all the entries in current directory |
{ # scope |
286 |
foreach my $path_key (keys %{$filesInBackup}) { |
my @stack; |
|
my @data = ( |
|
|
$shareID, |
|
|
$backupNum, |
|
|
$path_key, |
|
|
$filesInBackup->{$path_key}->{'relPath'}, |
|
|
$filesInBackup->{$path_key}->{'fullPath'}, |
|
|
# $filesInBackup->{$path_key}->{'sharePathM'}, |
|
|
$filesInBackup->{$path_key}->{'mtime'}, |
|
|
$filesInBackup->{$path_key}->{'type'}, |
|
|
$filesInBackup->{$path_key}->{'size'} |
|
|
); |
|
287 |
|
|
288 |
my $key = join(" ", ( |
my $files = BackupPC::View->new($bpc, $hostname, $backups); |
289 |
$shareID, |
my $filesInBackup = $files->dirAttrib($backupNum, $share, $dir); |
|
$dir, |
|
|
$path_key, |
|
|
$filesInBackup->{$path_key}->{'mtime'}, |
|
|
$filesInBackup->{$path_key}->{'size'} |
|
|
)); |
|
290 |
|
|
291 |
|
# first, add all the entries in current directory |
292 |
|
foreach my $path_key (keys %{$filesInBackup}) { |
293 |
|
my @data = ( |
294 |
|
$shareID, |
295 |
|
$backupNum, |
296 |
|
$path_key, |
297 |
|
$filesInBackup->{$path_key}->{'relPath'}, |
298 |
|
$filesInBackup->{$path_key}->{'fullPath'}, |
299 |
|
# $filesInBackup->{$path_key}->{'sharePathM'}, |
300 |
|
$filesInBackup->{$path_key}->{'mtime'}, |
301 |
|
$filesInBackup->{$path_key}->{'type'}, |
302 |
|
$filesInBackup->{$path_key}->{'size'} |
303 |
|
); |
304 |
|
|
305 |
|
my $key = join(" ", ( |
306 |
|
$shareID, |
307 |
|
$dir, |
308 |
|
$path_key, |
309 |
|
$filesInBackup->{$path_key}->{'mtime'}, |
310 |
|
$filesInBackup->{$path_key}->{'size'} |
311 |
|
)); |
312 |
|
|
313 |
|
|
314 |
|
if (! $beenThere->{$key} && ! found_in_db(@data)) { |
315 |
|
print STDERR "# key: $key [", $beenThere->{$key},"]" if ($debug >= 2); |
316 |
|
$sth->{'insert_files'}->execute(@data); |
317 |
|
if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) { |
318 |
|
$new_dirs++; |
319 |
|
print STDERR " dir\n" if ($debug >= 2); |
320 |
|
} else { |
321 |
|
$new_files++; |
322 |
|
print STDERR " file\n" if ($debug >= 2); |
323 |
|
} |
324 |
|
} |
325 |
|
$beenThere->{$key}++; |
326 |
|
|
|
if (! $beenThere->{$key} && ! found_in_db(@data)) { |
|
|
$sth->{'insert_files'}->execute(@data); |
|
|
# print STDERR "$key\n"; |
|
327 |
if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) { |
if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) { |
328 |
$new_dirs++; |
$nr_dirs++; |
329 |
|
|
330 |
|
my $full_path = $dir . '/' . $path_key; |
331 |
|
push @stack, $full_path; |
332 |
|
print STDERR "### store to stack: $full_path\n" if ($debug >= 3); |
333 |
|
|
334 |
|
# my ($f,$nf,$d,$nd) = recurseDir($bpc, $hostname, $backups, $backupNum, $share, $path_key, $shareID) unless ($beenThere->{$key}); |
335 |
|
# |
336 |
|
# $nr_files += $f; |
337 |
|
# $new_files += $nf; |
338 |
|
# $nr_dirs += $d; |
339 |
|
# $new_dirs += $nd; |
340 |
|
|
341 |
} else { |
} else { |
342 |
$new_files++; |
$nr_files++; |
343 |
} |
} |
344 |
} |
} |
|
$beenThere->{$key}++; |
|
|
|
|
|
if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) { |
|
|
$nr_dirs++; |
|
345 |
|
|
346 |
my ($f,$nf,$d,$nd) = recurseDir($bpc, $hostname, $backups, $backupNum, $share, $path_key, $shareID); |
print STDERR "## STACK ",join(", ", @stack),"\n" if ($debug >= 2); |
347 |
|
|
348 |
|
while ( my $dir = shift @stack ) { |
349 |
|
my ($f,$nf,$d,$nd) = recurseDir($bpc, $hostname, $backups, $backupNum, $share, $dir, $shareID); |
350 |
|
print STDERR "# $dir f: $f nf: $nf d: $d nd: $nd\n" if ($debug >= 1); |
351 |
$nr_files += $f; |
$nr_files += $f; |
352 |
$new_files += $nf; |
$new_files += $nf; |
353 |
$nr_dirs += $d; |
$nr_dirs += $d; |
354 |
$new_dirs += $nd; |
$new_dirs += $nd; |
|
|
|
|
} else { |
|
|
$nr_files++; |
|
355 |
} |
} |
356 |
} |
} |
357 |
|
|