1 |
#!/usr/local/bin/perl -w |
#!/usr/local/bin/perl -w |
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; |
11 |
use Time::HiRes qw/time/; |
use Time::HiRes qw/time/; |
12 |
use File::Pid; |
use File::Pid; |
13 |
use POSIX qw/strftime/; |
use POSIX qw/strftime/; |
14 |
|
|
15 |
use constant BPC_FTYPE_DIR => 5; |
use constant BPC_FTYPE_DIR => 5; |
16 |
|
|
17 |
my $debug = 0; |
my $debug = 0; |
282 |
|
|
283 |
sub found_in_db { |
sub found_in_db { |
284 |
|
|
285 |
my ($shareID,undef,$name,$path,undef,$date,undef,$size) = @_; |
my @data = @_; |
286 |
|
shift @data; |
287 |
|
|
288 |
|
my ($key, $shareID,undef,$name,$path,undef,$date,undef,$size) = @_; |
289 |
|
|
290 |
|
return $beenThere->{$key} if (defined($beenThere->{$key})); |
291 |
|
|
292 |
$sth->{file_in_db} ||= $dbh->prepare(qq{ |
$sth->{file_in_db} ||= $dbh->prepare(qq{ |
293 |
SELECT count(*) FROM files |
SELECT 1 FROM files |
294 |
WHERE shareID = ? and |
WHERE shareID = ? and |
295 |
path = ? and |
path = ? and |
296 |
name = ? and |
name = ? and |
300 |
|
|
301 |
my @param = ($shareID,$path,$name,$date,$size); |
my @param = ($shareID,$path,$name,$date,$size); |
302 |
$sth->{file_in_db}->execute(@param); |
$sth->{file_in_db}->execute(@param); |
303 |
my ($rows) = $sth->{file_in_db}->fetchrow_array(); |
my $rows = $sth->{file_in_db}->rows; |
304 |
print STDERR "## found_in_db ",( $rows ? '+' : '-' ), join(" ",@param), "\n" if ($debug >= 3); |
print STDERR "## found_in_db ",( $rows ? '+' : '-' ), join(" ",@param), "\n" if ($debug >= 3); |
305 |
|
|
306 |
|
$beenThere->{$key}++; |
307 |
|
|
308 |
|
$sth->{'insert_files'}->execute(@data) unless ($rows); |
309 |
return $rows; |
return $rows; |
310 |
} |
} |
311 |
|
|
350 |
)); |
)); |
351 |
|
|
352 |
|
|
353 |
if (! $beenThere->{$key} && ! found_in_db(@data)) { |
if (! defined($beenThere->{$key}) && ! found_in_db($key, @data)) { |
354 |
print STDERR "# key: $key [", $beenThere->{$key},"]" if ($debug >= 2); |
print STDERR "# key: $key [", $beenThere->{$key},"]" if ($debug >= 2); |
355 |
$sth->{'insert_files'}->execute(@data); |
|
356 |
if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) { |
if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) { |
357 |
$new_dirs++; |
$new_dirs++; |
358 |
print STDERR " dir\n" if ($debug >= 2); |
print STDERR " dir\n" if ($debug >= 2); |
361 |
print STDERR " file\n" if ($debug >= 2); |
print STDERR " file\n" if ($debug >= 2); |
362 |
} |
} |
363 |
} |
} |
|
$beenThere->{$key}++; |
|
364 |
|
|
365 |
if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) { |
if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) { |
366 |
$nr_dirs++; |
$nr_dirs++; |