check filesize of archives on disk with size in database
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 4 Jan 2011 15:37:21 +0000 (15:37 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 4 Jan 2011 15:37:21 +0000 (15:37 +0000)
bin/BackupPC_checkArchiveConsistency [new file with mode: 0755]

diff --git a/bin/BackupPC_checkArchiveConsistency b/bin/BackupPC_checkArchiveConsistency
new file mode 100755 (executable)
index 0000000..2a9b629
--- /dev/null
@@ -0,0 +1,50 @@
+#!/usr/local/bin/perl
+use strict;
+no utf8;
+
+use lib "/data/backuppc-agi//lib";
+use DBI;
+use BackupPC::Lib;
+
+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 $dvd_nr = $ARGV[0];
+
+if (!defined($dvd_nr)) {
+       print q{
+       No dvd_nr parameter! 
+       Usage:
+               $0 <dvd_nr>
+       };
+       exit(0);
+}
+
+my $sql = q{
+       SELECT * 
+       FROM backups_on_dvds
+       WHERE dvd_nr = ?
+};
+my $sth = $dbh->prepare($sql);
+$sth->execute($dvd_nr);
+while (my $row = $sth->fetchrow_hashref()) {
+       my $host_share = $row->{share};
+       $host_share =~ s/(.*?):(.*)/$1_$2_/gi;
+       my $filename = $tar_dir."/".$host_share . $row->{num}.".tar.gz";
+       my (undef, undef, undef, undef, undef, undef, undef, $fs_size, undef, undef, undef, undef, undef) = stat($filename);
+       print "checking $filename...";
+       if ($fs_size != $row->{gzip_size}) {
+               print "INVALID: fs_size: $fs_size, db_size: ".$row->{gzip_size}."\n";
+       } else {
+               print "ok\n";
+       }
+
+}
+$sth->finish();
+$dbh->disconnect();
+
+