/[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 381 - (show annotations)
Thu May 10 06:16:16 2007 UTC (17 years ago) by iklaric
File size: 1624 byte(s)
- removeBurnedArchives is tested - removes tgz's that are burned on two or more DVD archives
- checkArchiveConsistency for a given dvd_nr checks all the files that are on that DVD and compares filesize in the database with the one on the filesystem

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

  ViewVC Help
Powered by ViewVC 1.1.26