1 |
#!/usr/bin/perl -w |
2 |
use strict; |
3 |
no utf8; |
4 |
|
5 |
use lib "__INSTALLDIR__/lib"; |
6 |
use DBI; |
7 |
|
8 |
|
9 |
my $bpc = BackupPC::Lib->new || die "can't create BackupPC::Lib"; |
10 |
my %Conf = $bpc->Conf(); |
11 |
|
12 |
my $dsn = $Conf{searchdsn} || die "need searchdsn in config.pl\n"; |
13 |
my $user = $Conf{searchuser} || ''; |
14 |
my $dbh = dbi->connect($dsn, $user, "", { raiseerror => 1, autocommit => 0 }); |
15 |
my $tar_dir = $Conf{InstallDir}.'/'.$Conf{GzipTempDir}; |
16 |
my $sql = q{ |
17 |
SELECT hosts.name AS host, shares.name AS share, backups.num AS num, MAX(archive_burned.copy) |
18 |
FROM backups |
19 |
INNER JOIN hosts ON (hosts.id=backups.hostid) |
20 |
INNER JOIN shares ON (shares.id=backups.shareid) |
21 |
INNER JOIN archive_backup ON (archive_backup.backup_id=backups.id) |
22 |
INNER JOIN archive_burned ON (archive_burned.archive_id=archive_backup.archive_id) |
23 |
GROUP BY 1, 2, 3 |
24 |
HAVING MAX(archive_burned.copy)>=2; |
25 |
}; |
26 |
my $sth = $dbh->prepare($sql); |
27 |
my $totalRemoved = 0; |
28 |
$sth->execute(); |
29 |
|
30 |
while (my $row = $sth->fetchrow_hashref()) { |
31 |
my $filename = BackupPC::SearchLib::getGzipName($row->{'host'}, $row->{'share'}, $row->{'num'}); |
32 |
my (undef, undef, undef, undef, undef, undef, undef, $fs_size, undef, undef, undef, undef, undef) = stat($filename); |
33 |
$totalRemoved += $fs_size; |
34 |
if (system("rm $filename") != 0) { |
35 |
print "ERROR: unable to remove $filename.\n"; |
36 |
} |
37 |
} |
38 |
|
39 |
print "Finished. Freed $totalRemoved bytes (".($totalRemoved/(1024*1024))."MB\n"; |
40 |
|
41 |
$sth->finish(); |
42 |
$dbh->disconnect(); |