143 |
|
|
144 |
my $where = ''; |
my $where = ''; |
145 |
my @data; |
my @data; |
146 |
if ($host_id && $share_id && $num) { |
if (defined($host_id) && defined($share_id) && defined($num)) { |
147 |
$where = qq{ |
$where = qq{ |
148 |
WHERE |
WHERE |
149 |
hosts.id = ? AND |
hosts.id = ? AND |
209 |
$doc->add_attr('@uri', $uri); |
$doc->add_attr('@uri', $uri); |
210 |
|
|
211 |
foreach my $c (@{ $sth->{NAME} }) { |
foreach my $c (@{ $sth->{NAME} }) { |
212 |
$doc->add_attr($c, $row->{$c}) if ($row->{$c}); |
$doc->add_attr($c, $row->{$c}) if (defined($row->{$c})); |
213 |
} |
} |
214 |
|
|
215 |
#$doc->add_attr('@cdate', fmt_date($row->{'date'})); |
#$doc->add_attr('@cdate', fmt_date($row->{'date'})); |
256 |
|
|
257 |
|
|
258 |
## update index ## |
## update index ## |
259 |
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}) { |
260 |
# update all |
# update all |
261 |
print "force update of HyperEstraier index "; |
print "force update of HyperEstraier index "; |
262 |
print "importing existing data" unless (-e $index_path); |
print "importing existing data" unless (-e $TopDir . $index_path); |
263 |
print "by -i flag" if ($opt{i}); |
print "by -i flag" if ($opt{i}); |
264 |
print "by -j flag" if ($opt{j}); |
print "by -j flag" if ($opt{j}); |
265 |
print "\n"; |
print "\n"; |
278 |
} |
} |
279 |
|
|
280 |
print "creating tables...\n"; |
print "creating tables...\n"; |
281 |
|
|
282 |
$dbh->do(qq{ |
$dbh->do( qq{ |
283 |
create table hosts ( |
create table hosts ( |
284 |
ID SERIAL PRIMARY KEY, |
ID SERIAL PRIMARY KEY, |
285 |
name VARCHAR(30) NOT NULL, |
name VARCHAR(30) NOT NULL, |
286 |
IP VARCHAR(15) |
IP VARCHAR(15) |
287 |
); |
); |
288 |
}); |
|
|
|
|
|
$dbh->do(qq{ |
|
289 |
create table shares ( |
create table shares ( |
290 |
ID SERIAL PRIMARY KEY, |
ID SERIAL PRIMARY KEY, |
291 |
hostID INTEGER NOT NULL references hosts(id), |
hostID INTEGER NOT NULL references hosts(id), |
292 |
name VARCHAR(30) NOT NULL, |
name VARCHAR(30) NOT NULL, |
293 |
share VARCHAR(200) NOT NULL |
share VARCHAR(200) NOT NULL |
294 |
); |
); |
|
}); |
|
295 |
|
|
|
$dbh->do(qq{ |
|
296 |
create table dvds ( |
create table dvds ( |
297 |
ID SERIAL PRIMARY KEY, |
ID SERIAL PRIMARY KEY, |
298 |
num INTEGER NOT NULL, |
num INTEGER NOT NULL, |
299 |
name VARCHAR(255) NOT NULL, |
name VARCHAR(255) NOT NULL, |
300 |
mjesto VARCHAR(255) |
mjesto VARCHAR(255) |
301 |
); |
); |
302 |
}); |
|
|
|
|
|
$dbh->do(qq{ |
|
303 |
create table backups ( |
create table backups ( |
304 |
id serial, |
id serial, |
305 |
hostID INTEGER NOT NULL references hosts(id), |
hostID INTEGER NOT NULL references hosts(id), |
310 |
size bigint not null, |
size bigint not null, |
311 |
inc_size bigint not null default -1, |
inc_size bigint not null default -1, |
312 |
inc_deleted boolean default false, |
inc_deleted boolean default false, |
313 |
|
parts integer not null default 1, |
314 |
PRIMARY KEY(id) |
PRIMARY KEY(id) |
315 |
); |
); |
|
}); |
|
316 |
|
|
|
$dbh->do(qq{ |
|
317 |
create table files ( |
create table files ( |
318 |
ID SERIAL, |
ID SERIAL, |
319 |
shareID INTEGER NOT NULL references shares(id), |
shareID INTEGER NOT NULL references shares(id), |
325 |
size bigint NOT NULL, |
size bigint NOT NULL, |
326 |
primary key(id) |
primary key(id) |
327 |
); |
); |
|
}); |
|
328 |
|
|
|
|
|
|
$dbh->do( qq{ |
|
329 |
create table archive ( |
create table archive ( |
330 |
id serial, |
id serial, |
331 |
dvd_nr int not null, |
dvd_nr int not null, |
335 |
date timestamp default now(), |
date timestamp default now(), |
336 |
primary key(id) |
primary key(id) |
337 |
); |
); |
|
} |
|
|
); |
|
338 |
|
|
339 |
$dbh->do( qq{ |
create table archive_backup ( |
340 |
create table archive_backup |
archive_id int not null references archive(id) on delete cascade, |
|
( |
|
|
archive_id int not null references archive(id), |
|
341 |
backup_id int not null references backups(id), |
backup_id int not null references backups(id), |
342 |
primary key(archive_id, backup_id) |
primary key(archive_id, backup_id) |
343 |
); |
); |
344 |
|
|
345 |
|
create table archive_burned ( |
346 |
|
archive_id int references archive(id), |
347 |
|
date timestamp default now(), |
348 |
|
part int not null default 1, |
349 |
|
copy int not null default 1, |
350 |
|
iso_size bigint default -1 |
351 |
|
); |
352 |
|
|
353 |
|
create table backup_parts ( |
354 |
|
id serial, |
355 |
|
backup_id int references backups(id), |
356 |
|
part_nr int not null check (part_nr > 0), |
357 |
|
tar_size bigint not null check (tar_size > 0), |
358 |
|
size bigint not null check (size > 0), |
359 |
|
md5 text not null, |
360 |
|
items int not null check (items > 0), |
361 |
|
date timestamp default now(), |
362 |
|
primary key(id) |
363 |
|
); |
364 |
}); |
}); |
365 |
|
|
366 |
print "creating indexes: "; |
print "creating indexes: "; |
378 |
files:date |
files:date |
379 |
files:size |
files:size |
380 |
archive:dvd_nr |
archive:dvd_nr |
381 |
|
archive_burned:archive_id |
382 |
|
backup_parts:backup_id,part_nr |
383 |
)) { |
)) { |
384 |
do_index($index); |
do_index($index); |
385 |
} |
} |
630 |
$filesInBackup->{$path_key}->{'size'} |
$filesInBackup->{$path_key}->{'size'} |
631 |
)); |
)); |
632 |
|
|
633 |
|
# daylight saving time change offset for 1h |
634 |
|
my $dst_offset = 60 * 60; |
635 |
|
|
636 |
|
my $key_dst1 = join(" ", ( |
637 |
|
$shareID, |
638 |
|
$dir, |
639 |
|
$path_key, |
640 |
|
$filesInBackup->{$path_key}->{'mtime'} - $dst_offset, |
641 |
|
$filesInBackup->{$path_key}->{'size'} |
642 |
|
)); |
643 |
|
|
644 |
|
my $key_dst2 = join(" ", ( |
645 |
|
$shareID, |
646 |
|
$dir, |
647 |
|
$path_key, |
648 |
|
$filesInBackup->{$path_key}->{'mtime'} + $dst_offset, |
649 |
|
$filesInBackup->{$path_key}->{'size'} |
650 |
|
)); |
651 |
|
|
652 |
my $found; |
my $found; |
653 |
if (! defined($beenThere->{$key}) && ! ($found = found_in_db($key, @data)) ) { |
if ( |
654 |
|
! defined($beenThere->{$key}) && |
655 |
|
! defined($beenThere->{$key_dst1}) && |
656 |
|
! defined($beenThere->{$key_dst2}) && |
657 |
|
! ($found = found_in_db($key, @data)) |
658 |
|
) { |
659 |
print STDERR "# key: $key [", $beenThere->{$key},"]" if ($debug >= 2); |
print STDERR "# key: $key [", $beenThere->{$key},"]" if ($debug >= 2); |
660 |
|
|
661 |
if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) { |
if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) { |