date integer NOT NULL,
type CHAR(4) not null,
shareID integer not null references shares(id),
+ size integer not null,
PRIMARY KEY(hostID, num, shareID)
);
});
});
$sth->{insert_backups} = $dbh->prepare(qq{
-INSERT INTO backups (hostID, num, date, type, shareid)
-VALUES (?,?,?,?,?)
+INSERT INTO backups (hostID, num, date, type, shareid, size)
+VALUES (?,?,?,?,?,?)
});
$sth->{insert_files} = $dbh->prepare(qq{
# dump some log
print strftime($t_fmt,localtime())," ", $share;
- my ($f, $nf, $d, $nd) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID);
+ my ($f, $nf, $d, $nd, $size) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID);
$sth->{insert_backups}->execute(
$hostID,
$backupNum,
$backup->{'endTime'},
$backup->{'type'},
- $shareID
+ $shareID,
+ $size,
);
print " commit";
$dbh->commit();
my $dur = (time() - $t) || 1;
- 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",
$nf, $f, $nd, $d,
+ ($size / 1024 / 1024),
( ($f+$d) / $dur ),
fmt_time($dur)
);
print STDERR "\nrecurse($hostname,$backupNum,$share,$dir,$shareID)\n" if ($debug >= 1);
- 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);
{ # scope
my @stack;
# first, add all the entries in current directory
foreach my $path_key (keys %{$filesInBackup}) {
+ print STDERR "# file ",Dumper($filesInBackup->{$path_key}),"\n" if ($debug >= 3);
my @data = (
$shareID,
$backupNum,
$new_files++;
print STDERR " file\n" if ($debug >= 2);
}
+ $size += $filesInBackup->{$path_key}->{'size'} || 0;
}
if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {
print STDERR "## STACK ",join(", ", @stack),"\n" if ($debug >= 2);
while ( my $dir = shift @stack ) {
- 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);
print STDERR "# $dir f: $f nf: $nf d: $d nd: $nd\n" if ($debug >= 1);
$nr_files += $f;
$new_files += $nf;
$nr_dirs += $d;
$new_dirs += $nd;
+ $size += $s;
}
}
- return ($nr_files, $new_files, $nr_dirs, $new_dirs);
+ return ($nr_files, $new_files, $nr_dirs, $new_dirs, $size);
}
FROM files
INNER JOIN shares ON files.shareID=shares.ID
INNER JOIN hosts ON hosts.ID = shares.hostID
- INNER JOIN backups ON backups.num = files.backupNum and backups.hostID = hosts.ID
+ INNER JOIN backups ON backups.num = files.backupNum and backups.hostID = hosts.ID AND backups.shareID = shares.ID
};
my $sql_dvd_from = qq{
my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } );
my $sql = q{
SELECT
- hosts.ID AS hostid,
+ backups.hostID AS hostid,
min(hosts.name) AS host,
backups.num AS backupno,
min(backups.type) AS type,
- min(backups.date) AS date
- FROM backups, shares, files, hosts
+ min(backups.date) AS date,
+ min(backups.size) AS size
+ FROM backups
+ INNER JOIN hosts ON hosts.ID = backups.hostID
WHERE
- backups.num = files.backupNum AND
- shares.ID = files.shareID AND
- backups.hostID = shares.hostID AND
- hosts.ID = backups.hostID AND
files.dvdid IS NULL
GROUP BY
- backups.hostID, backups.num, hosts.id
+ backups.hostID, backups.num
ORDER BY min(backups.date)
};
my $sth = $dbh->prepare( $sql );
my @ret;
$sth->execute();
- while ( my $row = $sth->fetchrow_hashref() ) {
- push(@ret, {
- 'host' => $row->{'host'},
- 'hostid' => $row->{'hostid'},
- 'backupno' => $row->{'backupno'},
- 'type' => $row->{'type'},
- 'date' => $row->{'date'},
- 'age' => sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) ),
- }
- );
+ while ( my $row = $sth->fetchrow_hashref() ) {
+ $row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) );
+ $row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024);
+ push @ret, $row;
}
return @ret;
<td class="tableheader">Type</td>
<td class="tableheader">date</td>
<td class="tableheader">age/days</td>
+ <td class="tableheader">size/MB</td>
</tr>
};
'<td class="fviewborder">' . $backup->{'type'} . '</td>' .
'<td class="fviewborder">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .
'<td class="fviewborder">' . $backup->{'age'} . '</td>' .
+ '<td class="fviewborder">' . $backup->{'size'} . '</td>' .
'</tr>';
}