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