05f91bac3a9b4d0ec8e1d51d3e5d2daf836ac593
[BackupPC.git] / bin / BackupPC_checkArchiveConsistency
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
17
18 my $dvd_nr = $ARGV[0];
19
20 if (!defined($dvd_nr)) {
21         print q{
22         No dvd_nr parameter! 
23         Usage:
24                 $0 <dvd_nr>
25         };
26         exit(0);
27 }
28
29 my $sql = q{
30         SELECT * 
31         FROM backups_on_dvds
32         WHERE dvd_nr = ?
33 };
34 my $sth = $dbh->prepare($sql);
35 $sth->execute($dvd_nr);
36 while (my $row = $sth->fetchrow_hashref()) {
37         my $host_share = $row->{share};
38         $host_share =~ s/(.*)+:(.*)/$1_$2_/gi;
39         my $filename = $tar_dir."/".$host_share . $row->{num};
40         my (undef, undef, undef, undef, undef, undef, undef, $fs_size, undef, undef, undef, undef, undef) = stat($filename);
41         print "checking $filename...";
42         if ($fs_size != $row->{gzip_size}) {
43                 print "INVALID: fs_size: $fs_size, db_size: ".$row->{gzip_size}."\n";
44         } else {
45                 print "ok\n";
46         }
47
48 }
49 $sth->finish();
50 $dbh->disconnect();
51
52