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, |
120 |
fullpath VARCHAR(255) NOT NULL, |
fullpath VARCHAR(255) NOT NULL, |
156 |
} |
} |
157 |
print " done...\n"; |
print " done...\n"; |
158 |
|
|
159 |
eval { $dbh->commit; }; |
$dbh->commit; |
160 |
} |
} |
161 |
|
|
162 |
if ($opt{v}) { |
if ($opt{v}) { |
279 |
$dbh->commit(); |
$dbh->commit(); |
280 |
$dbh->disconnect(); |
$dbh->disconnect(); |
281 |
|
|
282 |
|
print "total duration: ",fmt_time(time() - $start_t),"\n"; |
283 |
|
|
284 |
$pidfile->remove; |
$pidfile->remove; |
285 |
|
|
286 |
sub getShareID() { |
sub getShareID() { |