--- trunk/bin/BackupPC_updatedb 2005/10/13 21:19:06 199 +++ trunk/bin/BackupPC_updatedb 2005/12/09 16:27:49 249 @@ -16,6 +16,9 @@ use constant BPC_FTYPE_DIR => 5; use constant EST_CHUNK => 100000; +# daylight saving time change offset for 1h +my $dst_offset = 60 * 60; + my $debug = 0; $|=1; @@ -50,9 +53,9 @@ my %opt; -if ( !getopts("cdm:v:ij", \%opt ) ) { +if ( !getopts("cdm:v:ijf", \%opt ) ) { print STDERR <add_attr('@uri', $uri); foreach my $c (@{ $sth->{NAME} }) { - $doc->add_attr($c, $row->{$c}) if ($row->{$c}); + $doc->add_attr($c, $row->{$c}) if (defined($row->{$c})); } #$doc->add_attr('@cdate', fmt_date($row->{'date'})); @@ -256,10 +269,10 @@ ## update index ## -if (($opt{i} || $opt{j} || ($index_path && ! -e $index_path)) && !$opt{c}) { +if (($opt{i} || $opt{j} || ($index_path && ! -e $TopDir . $index_path)) && !$opt{c}) { # update all print "force update of HyperEstraier index "; - print "importing existing data" unless (-e $index_path); + print "importing existing data" unless (-e $TopDir . $index_path); print "by -i flag" if ($opt{i}); print "by -j flag" if ($opt{j}); print "\n"; @@ -344,11 +357,23 @@ create table archive_burned ( archive_id int references archive(id), - date date default now(), + date timestamp default now(), part int not null default 1, + copy int not null default 1, iso_size bigint default -1 ); + create table backup_parts ( + id serial, + backup_id int references backups(id), + part_nr int not null check (part_nr > 0), + tar_size bigint not null check (tar_size > 0), + size bigint not null check (size > 0), + md5 text not null, + items int not null check (items > 0), + date timestamp default now(), + primary key(id) + ); }); print "creating indexes: "; @@ -367,6 +392,7 @@ files:size archive:dvd_nr archive_burned:archive_id + backup_parts:backup_id,part_nr )) { do_index($index); } @@ -421,7 +447,12 @@ $sth->{insert_backups} = $dbh->prepare(qq{ INSERT INTO backups (hostID, num, date, type, shareid, size) -VALUES (?,?,?,?,?,?) +VALUES (?,?,?,?,?,-1) +}); + +$sth->{update_backups_size} = $dbh->prepare(qq{ +UPDATE backups SET size = ? +WHERE hostID = ? and num = ? and date = ? and type =? and shareid = ? }); $sth->{insert_files} = $dbh->prepare(qq{ @@ -430,7 +461,10 @@ VALUES (?,?,?,?,?,?,?) }); -foreach my $host_key (keys %{$hosts}) { +my @hosts = keys %{$hosts}; +my $host_nr = 0; + +foreach my $host_key (@hosts) { my $hostname = $hosts->{$host_key}->{'host'} || die "can't find host for $host_key"; @@ -445,7 +479,9 @@ $hostID = $dbh->last_insert_id(undef,undef,'hosts',undef); } - print "host ".$hosts->{$host_key}->{'host'}.": "; + $host_nr++; + print "host ", $hosts->{$host_key}->{'host'}, " [", + $host_nr, "/", ($#hosts + 1), "]: "; # get backups for a host my @backups = $bpc->BackupInfoRead($hostname); @@ -487,15 +523,23 @@ # dump some log print curr_time," ", $share; - my ($f, $nf, $d, $nd, $size) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID); - $sth->{insert_backups}->execute( $hostID, $backupNum, $backup->{'endTime'}, substr($backup->{'type'},0,4), $shareID, + ); + + my ($f, $nf, $d, $nd, $size) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID); + + $sth->{update_backups_size}->execute( $size, + $hostID, + $backupNum, + $backup->{'endTime'}, + substr($backup->{'type'},0,4), + $shareID, ); print " commit"; @@ -562,12 +606,12 @@ SELECT 1 FROM files WHERE shareID = ? and path = ? and - date = ? and - size = ? + size = ? and + ( date = ? or date = ? or date = ? ) LIMIT 1 }); - my @param = ($shareID,$path,$date,$size); + my @param = ($shareID,$path,$size,$date, $date-$dst_offset, $date+$dst_offset); $sth->{file_in_db}->execute(@param); my $rows = $sth->{file_in_db}->rows; print STDERR "## found_in_db($shareID,$path,$date,$size) ",( $rows ? '+' : '-' ), join(" ",@param), "\n" if ($debug >= 3); @@ -617,8 +661,29 @@ $filesInBackup->{$path_key}->{'size'} )); + my $key_dst_prev = join(" ", ( + $shareID, + $dir, + $path_key, + $filesInBackup->{$path_key}->{'mtime'} - $dst_offset, + $filesInBackup->{$path_key}->{'size'} + )); + + my $key_dst_next = join(" ", ( + $shareID, + $dir, + $path_key, + $filesInBackup->{$path_key}->{'mtime'} + $dst_offset, + $filesInBackup->{$path_key}->{'size'} + )); + my $found; - if (! defined($beenThere->{$key}) && ! ($found = found_in_db($key, @data)) ) { + if ( + ! defined($beenThere->{$key}) && + ! defined($beenThere->{$key_dst_prev}) && + ! defined($beenThere->{$key_dst_next}) && + ! ($found = found_in_db($key, @data)) + ) { print STDERR "# key: $key [", $beenThere->{$key},"]" if ($debug >= 2); if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {