/[BackupPC]/trunk/bin/BackupPC_removeBurnedArchives
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/bin/BackupPC_removeBurnedArchives

Parent Directory Parent Directory | Revision Log Revision Log


Revision 375 - (show annotations)
Tue May 8 07:34:19 2007 UTC (17 years, 1 month ago) by iklaric
File size: 1414 byte(s)
- added utilities for checking archive consistency and removing backups that have been burned 2 or more files
- STILL EXPERIMENTAL!

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();

  ViewVC Help
Powered by ViewVC 1.1.26