95 |
num INTEGER NOT NULL, |
num INTEGER NOT NULL, |
96 |
date integer NOT NULL, |
date integer NOT NULL, |
97 |
type CHAR(4) not null, |
type CHAR(4) not null, |
98 |
PRIMARY KEY(hostID, num) |
shareID integer not null references shares(id), |
99 |
|
size integer not null, |
100 |
|
PRIMARY KEY(hostID, num, shareID) |
101 |
); |
); |
102 |
}); |
}); |
103 |
|
|
104 |
do_index('backups_hostid,num_unique'); |
#do_index('backups_hostid,num_unique'); |
105 |
|
|
106 |
$dbh->do(qq{ |
$dbh->do(qq{ |
107 |
create table dvds ( |
create table dvds ( |
119 |
backupNum INTEGER NOT NULL, |
backupNum INTEGER NOT NULL, |
120 |
name VARCHAR(255) NOT NULL, |
name VARCHAR(255) NOT NULL, |
121 |
path VARCHAR(255) NOT NULL, |
path VARCHAR(255) NOT NULL, |
|
fullpath VARCHAR(255) NOT NULL, |
|
122 |
date integer NOT NULL, |
date integer NOT NULL, |
123 |
type INTEGER NOT NULL, |
type INTEGER NOT NULL, |
124 |
size INTEGER NOT NULL, |
size INTEGER NOT NULL, |
182 |
SELECT ID FROM hosts WHERE name=? |
SELECT ID FROM hosts WHERE name=? |
183 |
}); |
}); |
184 |
|
|
185 |
$sth->{backups_broj} = $dbh->prepare(qq{ |
$sth->{backups_count} = $dbh->prepare(qq{ |
186 |
SELECT COUNT(*) |
SELECT COUNT(*) |
187 |
FROM backups |
FROM backups |
188 |
WHERE hostID=? AND num=? |
WHERE hostID=? AND num=? AND shareid=? |
189 |
}); |
}); |
190 |
|
|
191 |
$sth->{insert_backups} = $dbh->prepare(qq{ |
$sth->{insert_backups} = $dbh->prepare(qq{ |
192 |
INSERT INTO backups (hostID, num, date, type) |
INSERT INTO backups (hostID, num, date, type, shareid, size) |
193 |
VALUES (?,?,?,?) |
VALUES (?,?,?,?,?,?) |
194 |
}); |
}); |
195 |
|
|
196 |
$sth->{insert_files} = $dbh->prepare(qq{ |
$sth->{insert_files} = $dbh->prepare(qq{ |
197 |
INSERT INTO files |
INSERT INTO files |
198 |
(shareID, backupNum, name, path, fullpath, date, type, size) |
(shareID, backupNum, name, path, date, type, size) |
199 |
VALUES (?,?,?,?,?,?,?,?) |
VALUES (?,?,?,?,?,?,?) |
200 |
}); |
}); |
201 |
|
|
202 |
sub fmt_time { |
sub fmt_time { |
248 |
fmt_time($backup->{endTime} - $backup->{startTime}), |
fmt_time($backup->{endTime} - $backup->{startTime}), |
249 |
")\n"; |
")\n"; |
250 |
|
|
|
$sth->{backups_broj}->execute($hostID, $backupNum); |
|
|
my ($broj) = $sth->{backups_broj}->fetchrow_array(); |
|
|
next if ($broj > 0); |
|
|
|
|
|
$sth->{insert_backups}->execute( |
|
|
$hostID, |
|
|
$backupNum, |
|
|
$backup->{'endTime'}, |
|
|
$backup->{'type'} |
|
|
); |
|
|
$dbh->commit(); |
|
|
|
|
251 |
my $files = BackupPC::View->new($bpc, $hostname, \@backups, 1); |
my $files = BackupPC::View->new($bpc, $hostname, \@backups, 1); |
252 |
foreach my $share ($files->shareList($backupNum)) { |
foreach my $share ($files->shareList($backupNum)) { |
253 |
|
|
254 |
my $t = time(); |
my $t = time(); |
255 |
|
|
|
print strftime($t_fmt,localtime())," ", $share; |
|
256 |
$shareID = getShareID($share, $hostID, $hostname); |
$shareID = getShareID($share, $hostID, $hostname); |
257 |
|
|
258 |
my ($f, $nf, $d, $nd) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID); |
$sth->{backups_count}->execute($hostID, $backupNum, $shareID); |
259 |
|
my ($count) = $sth->{backups_count}->fetchrow_array(); |
260 |
|
# skip if allready in database! |
261 |
|
next if ($count > 0); |
262 |
|
|
263 |
|
# dump some log |
264 |
|
print strftime($t_fmt,localtime())," ", $share; |
265 |
|
|
266 |
|
my ($f, $nf, $d, $nd, $size) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID); |
267 |
|
|
268 |
|
$sth->{insert_backups}->execute( |
269 |
|
$hostID, |
270 |
|
$backupNum, |
271 |
|
$backup->{'endTime'}, |
272 |
|
$backup->{'type'}, |
273 |
|
$shareID, |
274 |
|
$size, |
275 |
|
); |
276 |
|
|
277 |
|
print " commit"; |
278 |
|
$dbh->commit(); |
279 |
|
|
280 |
my $dur = (time() - $t) || 1; |
my $dur = (time() - $t) || 1; |
281 |
printf(" %d/%d files %d/%d dirs [%.2f/s dur: %s]\n", |
printf(" %d/%d files %d/%d dirs %0.2f MB [%.2f/s dur: %s]\n", |
282 |
$nf, $f, $nd, $d, |
$nf, $f, $nd, $d, |
283 |
|
($size / 1024 / 1024), |
284 |
( ($f+$d) / $dur ), |
( ($f+$d) / $dur ), |
285 |
fmt_time($dur) |
fmt_time($dur) |
286 |
); |
); |
|
$dbh->commit(); |
|
287 |
} |
} |
288 |
|
|
289 |
} |
} |
362 |
|
|
363 |
print STDERR "\nrecurse($hostname,$backupNum,$share,$dir,$shareID)\n" if ($debug >= 1); |
print STDERR "\nrecurse($hostname,$backupNum,$share,$dir,$shareID)\n" if ($debug >= 1); |
364 |
|
|
365 |
my ($nr_files, $new_files, $nr_dirs, $new_dirs) = (0,0,0,0); |
my ($nr_files, $new_files, $nr_dirs, $new_dirs, $size) = (0,0,0,0,0); |
366 |
|
|
367 |
{ # scope |
{ # scope |
368 |
my @stack; |
my @stack; |
372 |
|
|
373 |
# first, add all the entries in current directory |
# first, add all the entries in current directory |
374 |
foreach my $path_key (keys %{$filesInBackup}) { |
foreach my $path_key (keys %{$filesInBackup}) { |
375 |
|
print STDERR "# file ",Dumper($filesInBackup->{$path_key}),"\n" if ($debug >= 3); |
376 |
my @data = ( |
my @data = ( |
377 |
$shareID, |
$shareID, |
378 |
$backupNum, |
$backupNum, |
379 |
$path_key, |
$path_key, |
380 |
$filesInBackup->{$path_key}->{'relPath'}, |
$filesInBackup->{$path_key}->{'relPath'}, |
|
$filesInBackup->{$path_key}->{'fullPath'}, |
|
|
# $filesInBackup->{$path_key}->{'sharePathM'}, |
|
381 |
$filesInBackup->{$path_key}->{'mtime'}, |
$filesInBackup->{$path_key}->{'mtime'}, |
382 |
$filesInBackup->{$path_key}->{'type'}, |
$filesInBackup->{$path_key}->{'type'}, |
383 |
$filesInBackup->{$path_key}->{'size'} |
$filesInBackup->{$path_key}->{'size'} |
402 |
$new_files++; |
$new_files++; |
403 |
print STDERR " file\n" if ($debug >= 2); |
print STDERR " file\n" if ($debug >= 2); |
404 |
} |
} |
405 |
|
$size += $filesInBackup->{$path_key}->{'size'} || 0; |
406 |
} |
} |
407 |
|
|
408 |
if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) { |
if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) { |
427 |
print STDERR "## STACK ",join(", ", @stack),"\n" if ($debug >= 2); |
print STDERR "## STACK ",join(", ", @stack),"\n" if ($debug >= 2); |
428 |
|
|
429 |
while ( my $dir = shift @stack ) { |
while ( my $dir = shift @stack ) { |
430 |
my ($f,$nf,$d,$nd) = recurseDir($bpc, $hostname, $files, $backupNum, $share, $dir, $shareID); |
my ($f,$nf,$d,$nd, $s) = recurseDir($bpc, $hostname, $files, $backupNum, $share, $dir, $shareID); |
431 |
print STDERR "# $dir f: $f nf: $nf d: $d nd: $nd\n" if ($debug >= 1); |
print STDERR "# $dir f: $f nf: $nf d: $d nd: $nd\n" if ($debug >= 1); |
432 |
$nr_files += $f; |
$nr_files += $f; |
433 |
$new_files += $nf; |
$new_files += $nf; |
434 |
$nr_dirs += $d; |
$nr_dirs += $d; |
435 |
$new_dirs += $nd; |
$new_dirs += $nd; |
436 |
|
$size += $s; |
437 |
} |
} |
438 |
} |
} |
439 |
|
|
440 |
return ($nr_files, $new_files, $nr_dirs, $new_dirs); |
return ($nr_files, $new_files, $nr_dirs, $new_dirs, $size); |
441 |
} |
} |
442 |
|
|