--- /dev/null
+#!/usr/bin/perl -w
+use strict;
+no utf8;
+
+use lib "__INSTALLDIR__/lib";
+use DBI;
+
+
+my $bpc = BackupPC::Lib->new || die "can't create BackupPC::Lib";
+my %Conf = $bpc->Conf();
+
+my $dsn = $Conf{searchdsn} || die "need searchdsn in config.pl\n";
+my $user = $Conf{searchuser} || '';
+my $dbh = dbi->connect($dsn, $user, "", { raiseerror => 1, autocommit => 0 });
+my $tar_dir = $Conf{InstallDir}.'/'.$Conf{GzipTempDir};
+my $sql = q{
+ SELECT hosts.name AS host, shares.name AS share, backups.num AS num, MAX(archive_burned.copy)
+ FROM backups
+ INNER JOIN hosts ON (hosts.id=backups.hostid)
+ INNER JOIN shares ON (shares.id=backups.shareid)
+ INNER JOIN archive_backup ON (archive_backup.backup_id=backups.id)
+ INNER JOIN archive_burned ON (archive_burned.archive_id=archive_backup.archive_id)
+ GROUP BY 1, 2, 3
+ HAVING MAX(archive_burned.copy)>=2;
+};
+my $sth = $dbh->prepare($sql);
+my $totalRemoved = 0;
+$sth->execute();
+
+while (my $row = $sth->fetchrow_hashref()) {
+ my $filename = BackupPC::SearchLib::getGzipName($row->{'host'}, $row->{'share'}, $row->{'num'});
+ my (undef, undef, undef, undef, undef, undef, undef, $fs_size, undef, undef, undef, undef, undef) = stat($filename);
+ $totalRemoved += $fs_size;
+ if (system("rm $filename") != 0) {
+ print "ERROR: unable to remove $filename.\n";
+ }
+}
+
+print "Finished. Freed $totalRemoved bytes (".($totalRemoved/(1024*1024))."MB\n";
+
+$sth->finish();
+$dbh->disconnect();