17 |
my $debug = 0; |
my $debug = 0; |
18 |
$|=1; |
$|=1; |
19 |
|
|
20 |
|
my $start_t = time(); |
21 |
|
|
22 |
my $pidfile = new File::Pid; |
my $pidfile = new File::Pid; |
23 |
|
|
24 |
if (my $pid = $pidfile->running ) { |
if (my $pid = $pidfile->running ) { |
38 |
my $TopDir = $bpc->TopDir(); |
my $TopDir = $bpc->TopDir(); |
39 |
my $beenThere = {}; |
my $beenThere = {}; |
40 |
|
|
41 |
my $dsn = "dbi:SQLite:dbname=$TopDir/$Conf{SearchDB}"; |
my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n"; |
42 |
my $user = ''; |
my $user = $Conf{SearchUser} || ''; |
|
|
|
|
# DEBUG option! |
|
|
($dsn,$user) = qw/dbi:Pg:dbname=backuppc dpavlin/; |
|
43 |
|
|
44 |
my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 }); |
my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 }); |
45 |
|
|
65 |
my $index = shift || return; |
my $index = shift || return; |
66 |
my ($table,$col,$unique) = split(/_/, $index); |
my ($table,$col,$unique) = split(/_/, $index); |
67 |
$unique ||= ''; |
$unique ||= ''; |
68 |
|
$index =~ s/,/_/g; |
69 |
$dbh->do(qq{ create $unique index $index on $table($col) }); |
$dbh->do(qq{ create $unique index $index on $table($col) }); |
70 |
} |
} |
71 |
|
|
99 |
); |
); |
100 |
}); |
}); |
101 |
|
|
102 |
do_index('backups_num_unique'); |
do_index('backups_hostid,num_unique'); |
103 |
|
|
104 |
$dbh->do(qq{ |
$dbh->do(qq{ |
105 |
create table dvds ( |
create table dvds ( |
114 |
create table files ( |
create table files ( |
115 |
ID SERIAL PRIMARY KEY, |
ID SERIAL PRIMARY KEY, |
116 |
shareID INTEGER NOT NULL references shares(id), |
shareID INTEGER NOT NULL references shares(id), |
117 |
backupNum INTEGER NOT NULL references backups(num), |
backupNum INTEGER NOT NULL, |
118 |
name VARCHAR(255) NOT NULL, |
name VARCHAR(255) NOT NULL, |
119 |
path VARCHAR(255) NOT NULL, |
path VARCHAR(255) NOT NULL, |
|
fullpath VARCHAR(255) NOT NULL, |
|
120 |
date integer NOT NULL, |
date integer NOT NULL, |
121 |
type INTEGER NOT NULL, |
type INTEGER NOT NULL, |
122 |
size INTEGER NOT NULL, |
size INTEGER NOT NULL, |
155 |
} |
} |
156 |
print " done...\n"; |
print " done...\n"; |
157 |
|
|
158 |
eval { $dbh->commit; }; |
$dbh->commit; |
159 |
} |
} |
160 |
|
|
161 |
if ($opt{v}) { |
if ($opt{v}) { |
193 |
|
|
194 |
$sth->{insert_files} = $dbh->prepare(qq{ |
$sth->{insert_files} = $dbh->prepare(qq{ |
195 |
INSERT INTO files |
INSERT INTO files |
196 |
(shareID, backupNum, name, path, fullpath, date, type, size) |
(shareID, backupNum, name, path, date, type, size) |
197 |
VALUES (?,?,?,?,?,?,?,?) |
VALUES (?,?,?,?,?,?,?) |
198 |
}); |
}); |
199 |
|
|
200 |
|
sub fmt_time { |
201 |
|
my $t = shift || return; |
202 |
|
my $out = ""; |
203 |
|
my ($ss,$mm,$hh) = gmtime($t); |
204 |
|
$out .= "${hh}h" if ($hh); |
205 |
|
$out .= sprintf("%02d:%02d", $mm,$ss); |
206 |
|
return $out; |
207 |
|
} |
208 |
|
|
209 |
foreach my $host_key (keys %{$hosts}) { |
foreach my $host_key (keys %{$hosts}) { |
210 |
|
|
211 |
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"; |
240 |
print $hosts->{$host_key}->{'host'}, |
print $hosts->{$host_key}->{'host'}, |
241 |
"\t#$backupNum\t", $backup->{type} || '?', " ", |
"\t#$backupNum\t", $backup->{type} || '?', " ", |
242 |
$backup->{nFilesNew} || '?', "/", $backup->{nFiles} || '?', |
$backup->{nFilesNew} || '?', "/", $backup->{nFiles} || '?', |
243 |
" files\n"; |
" files (date: ", |
244 |
|
strftime($t_fmt,localtime($backup->{startTime})), |
245 |
|
" dur: ", |
246 |
|
fmt_time($backup->{endTime} - $backup->{startTime}), |
247 |
|
")\n"; |
248 |
|
|
249 |
$sth->{backups_broj}->execute($hostID, $backupNum); |
$sth->{backups_broj}->execute($hostID, $backupNum); |
250 |
my ($broj) = $sth->{backups_broj}->fetchrow_array(); |
my ($broj) = $sth->{backups_broj}->fetchrow_array(); |
267 |
$shareID = getShareID($share, $hostID, $hostname); |
$shareID = getShareID($share, $hostID, $hostname); |
268 |
|
|
269 |
my ($f, $nf, $d, $nd) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID); |
my ($f, $nf, $d, $nd) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID); |
270 |
printf(" %d/%d files %d/%d dirs [%.2f/s]\n", |
my $dur = (time() - $t) || 1; |
271 |
|
printf(" %d/%d files %d/%d dirs [%.2f/s dur: %s]\n", |
272 |
$nf, $f, $nd, $d, |
$nf, $f, $nd, $d, |
273 |
( ($f+$d) / ((time() - $t) || 1) ) |
( ($f+$d) / $dur ), |
274 |
|
fmt_time($dur) |
275 |
); |
); |
276 |
$dbh->commit(); |
$dbh->commit(); |
277 |
} |
} |
282 |
$dbh->commit(); |
$dbh->commit(); |
283 |
$dbh->disconnect(); |
$dbh->disconnect(); |
284 |
|
|
285 |
|
print "total duration: ",fmt_time(time() - $start_t),"\n"; |
286 |
|
|
287 |
$pidfile->remove; |
$pidfile->remove; |
288 |
|
|
289 |
sub getShareID() { |
sub getShareID() { |
367 |
$backupNum, |
$backupNum, |
368 |
$path_key, |
$path_key, |
369 |
$filesInBackup->{$path_key}->{'relPath'}, |
$filesInBackup->{$path_key}->{'relPath'}, |
|
$filesInBackup->{$path_key}->{'fullPath'}, |
|
|
# $filesInBackup->{$path_key}->{'sharePathM'}, |
|
370 |
$filesInBackup->{$path_key}->{'mtime'}, |
$filesInBackup->{$path_key}->{'mtime'}, |
371 |
$filesInBackup->{$path_key}->{'type'}, |
$filesInBackup->{$path_key}->{'type'}, |
372 |
$filesInBackup->{$path_key}->{'size'} |
$filesInBackup->{$path_key}->{'size'} |