16 |
use constant BPC_FTYPE_DIR => 5; |
use constant BPC_FTYPE_DIR => 5; |
17 |
use constant EST_CHUNK => 100000; |
use constant EST_CHUNK => 100000; |
18 |
|
|
19 |
|
# daylight saving time change offset for 1h |
20 |
|
my $dst_offset = 60 * 60; |
21 |
|
|
22 |
my $debug = 0; |
my $debug = 0; |
23 |
$|=1; |
$|=1; |
24 |
|
|
53 |
|
|
54 |
my %opt; |
my %opt; |
55 |
|
|
56 |
if ( !getopts("cdm:v:ij", \%opt ) ) { |
if ( !getopts("cdm:v:ijf", \%opt ) ) { |
57 |
print STDERR <<EOF; |
print STDERR <<EOF; |
58 |
usage: $0 [-c|-d] [-m num] [-v|-v level] [-i] |
usage: $0 [-c|-d] [-m num] [-v|-v level] [-i|-j|-f] |
59 |
|
|
60 |
Options: |
Options: |
61 |
-c create database on first use |
-c create database on first use |
64 |
-v num set verbosity (debug) level (default $debug) |
-v num set verbosity (debug) level (default $debug) |
65 |
-i update Hyper Estraier full text index |
-i update Hyper Estraier full text index |
66 |
-j update full text, don't check existing files |
-j update full text, don't check existing files |
67 |
|
-f don't do anything with full text index |
68 |
|
|
69 |
Option -j is variation on -i. It will allow faster initial creation |
Option -j is variation on -i. It will allow faster initial creation |
70 |
of full-text index from existing database. |
of full-text index from existing database. |
71 |
|
|
72 |
|
Option -f will create database which is out of sync with full text index. You |
73 |
|
will have to re-run $0 with -i to fix it. |
74 |
|
|
75 |
EOF |
EOF |
76 |
exit 1; |
exit 1; |
77 |
} |
} |
79 |
if ($opt{v}) { |
if ($opt{v}) { |
80 |
print "Debug level at $opt{v}\n"; |
print "Debug level at $opt{v}\n"; |
81 |
$debug = $opt{v}; |
$debug = $opt{v}; |
82 |
|
} elsif ($opt{f}) { |
83 |
|
print "WARNING: disabling full-text index update. You need to re-run $0 -j !\n"; |
84 |
|
($use_hest, $index_path, $index_node_url) = (undef, undef, undef); |
85 |
} |
} |
86 |
|
|
87 |
#---- subs ---- |
#---- subs ---- |
121 |
|
|
122 |
my $skip_check = $opt{j} && print STDERR "Skipping check for existing files -- this should be used only with initital import\n"; |
my $skip_check = $opt{j} && print STDERR "Skipping check for existing files -- this should be used only with initital import\n"; |
123 |
|
|
124 |
unless ($use_hest) { |
unless (defined($use_hest)) { |
125 |
print STDERR "HyperEstraier support not enabled in configuration\n"; |
print STDERR "HyperEstraier support not enabled in configuration\n"; |
126 |
|
$use_hest = 0; |
127 |
return; |
return; |
128 |
} |
} |
129 |
|
|
445 |
|
|
446 |
$sth->{insert_backups} = $dbh->prepare(qq{ |
$sth->{insert_backups} = $dbh->prepare(qq{ |
447 |
INSERT INTO backups (hostID, num, date, type, shareid, size) |
INSERT INTO backups (hostID, num, date, type, shareid, size) |
448 |
VALUES (?,?,?,?,?,?) |
VALUES (?,?,?,?,?,-1) |
449 |
|
}); |
450 |
|
|
451 |
|
$sth->{update_backups_size} = $dbh->prepare(qq{ |
452 |
|
UPDATE backups SET size = ? |
453 |
|
WHERE hostID = ? and num = ? and date = ? and type =? and shareid = ? |
454 |
}); |
}); |
455 |
|
|
456 |
$sth->{insert_files} = $dbh->prepare(qq{ |
$sth->{insert_files} = $dbh->prepare(qq{ |
459 |
VALUES (?,?,?,?,?,?,?) |
VALUES (?,?,?,?,?,?,?) |
460 |
}); |
}); |
461 |
|
|
462 |
foreach my $host_key (keys %{$hosts}) { |
my @hosts = keys %{$hosts}; |
463 |
|
my $host_nr = 0; |
464 |
|
|
465 |
|
foreach my $host_key (@hosts) { |
466 |
|
|
467 |
my $hostname = $hosts->{$host_key}->{'host'} || die "can't find host for $host_key"; |
my $hostname = $hosts->{$host_key}->{'host'} || die "can't find host for $host_key"; |
468 |
|
|
477 |
$hostID = $dbh->last_insert_id(undef,undef,'hosts',undef); |
$hostID = $dbh->last_insert_id(undef,undef,'hosts',undef); |
478 |
} |
} |
479 |
|
|
480 |
print "host ".$hosts->{$host_key}->{'host'}.": "; |
$host_nr++; |
481 |
|
print "host ", $hosts->{$host_key}->{'host'}, " [", |
482 |
|
$host_nr, "/", ($#hosts + 1), "]: "; |
483 |
|
|
484 |
# get backups for a host |
# get backups for a host |
485 |
my @backups = $bpc->BackupInfoRead($hostname); |
my @backups = $bpc->BackupInfoRead($hostname); |
521 |
# dump some log |
# dump some log |
522 |
print curr_time," ", $share; |
print curr_time," ", $share; |
523 |
|
|
|
my ($f, $nf, $d, $nd, $size) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID); |
|
|
|
|
524 |
$sth->{insert_backups}->execute( |
$sth->{insert_backups}->execute( |
525 |
$hostID, |
$hostID, |
526 |
$backupNum, |
$backupNum, |
527 |
$backup->{'endTime'}, |
$backup->{'endTime'}, |
528 |
substr($backup->{'type'},0,4), |
substr($backup->{'type'},0,4), |
529 |
$shareID, |
$shareID, |
530 |
|
); |
531 |
|
|
532 |
|
my ($f, $nf, $d, $nd, $size) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID); |
533 |
|
|
534 |
|
$sth->{update_backups_size}->execute( |
535 |
$size, |
$size, |
536 |
|
$hostID, |
537 |
|
$backupNum, |
538 |
|
$backup->{'endTime'}, |
539 |
|
substr($backup->{'type'},0,4), |
540 |
|
$shareID, |
541 |
); |
); |
542 |
|
|
543 |
print " commit"; |
print " commit"; |
604 |
SELECT 1 FROM files |
SELECT 1 FROM files |
605 |
WHERE shareID = ? and |
WHERE shareID = ? and |
606 |
path = ? and |
path = ? and |
607 |
date = ? and |
size = ? and |
608 |
size = ? |
( date = ? or date = ? or date = ? ) |
609 |
LIMIT 1 |
LIMIT 1 |
610 |
}); |
}); |
611 |
|
|
612 |
my @param = ($shareID,$path,$date,$size); |
my @param = ($shareID,$path,$size,$date, $date-$dst_offset, $date+$dst_offset); |
613 |
$sth->{file_in_db}->execute(@param); |
$sth->{file_in_db}->execute(@param); |
614 |
my $rows = $sth->{file_in_db}->rows; |
my $rows = $sth->{file_in_db}->rows; |
615 |
print STDERR "## found_in_db($shareID,$path,$date,$size) ",( $rows ? '+' : '-' ), join(" ",@param), "\n" if ($debug >= 3); |
print STDERR "## found_in_db($shareID,$path,$date,$size) ",( $rows ? '+' : '-' ), join(" ",@param), "\n" if ($debug >= 3); |
659 |
$filesInBackup->{$path_key}->{'size'} |
$filesInBackup->{$path_key}->{'size'} |
660 |
)); |
)); |
661 |
|
|
662 |
# daylight saving time change offset for 1h |
my $key_dst_prev = join(" ", ( |
|
my $dst_offset = 60 * 60; |
|
|
|
|
|
my $key_dst1 = join(" ", ( |
|
663 |
$shareID, |
$shareID, |
664 |
$dir, |
$dir, |
665 |
$path_key, |
$path_key, |
667 |
$filesInBackup->{$path_key}->{'size'} |
$filesInBackup->{$path_key}->{'size'} |
668 |
)); |
)); |
669 |
|
|
670 |
my $key_dst2 = join(" ", ( |
my $key_dst_next = join(" ", ( |
671 |
$shareID, |
$shareID, |
672 |
$dir, |
$dir, |
673 |
$path_key, |
$path_key, |
678 |
my $found; |
my $found; |
679 |
if ( |
if ( |
680 |
! defined($beenThere->{$key}) && |
! defined($beenThere->{$key}) && |
681 |
! defined($beenThere->{$key_dst1}) && |
! defined($beenThere->{$key_dst_prev}) && |
682 |
! defined($beenThere->{$key_dst2}) && |
! defined($beenThere->{$key_dst_next}) && |
683 |
! ($found = found_in_db($key, @data)) |
! ($found = found_in_db($key, @data)) |
684 |
) { |
) { |
685 |
print STDERR "# key: $key [", $beenThere->{$key},"]" if ($debug >= 2); |
print STDERR "# key: $key [", $beenThere->{$key},"]" if ($debug >= 2); |