File: BackupPC_poolCntPrint

package info (click to toggle)
backuppc 4.4.0-11
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,752 kB
  • sloc: perl: 37,523; sh: 607; javascript: 176; makefile: 38; ansic: 6
file content (90 lines) | stat: -rwxr-xr-x 2,716 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/perl
#============================================================= -*-perl-*-
#
# BackupPC_poolCntPrint: print the contents of pool count and
#  pool count delta files.
#
# DESCRIPTION
#
#   Usage: BackupPC_poolCntPrint poolCntFilePath
#
# AUTHOR
#   Craig Barratt  <cbarratt@users.sourceforge.net>
#
# COPYRIGHT
#   Copyright (C) 2005-2020  Craig Barratt
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#========================================================================
#
# Version 4.4.0, released 20 Jun 2020.
#
# See http://backuppc.sourceforge.net.
#
#========================================================================

use strict;
no utf8;
use lib "__INSTALLDIR__/lib";

use BackupPC::Lib;
use BackupPC::XS;
use Data::Dumper;

die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );

my $TopDir = $bpc->TopDir();
my $BinDir = $bpc->BinDir();
my %Conf   = $bpc->Conf();
my $s      = $bpc->{storage};
my $digest;

if ( @ARGV == 0 ) {
    print STDERR "Usage: $0 [poolCntFilePath|hexDigest]...\n";
    exit(1);
}
while ( my $poolCntFile = shift(@ARGV) ) {
    if ( !-f $poolCntFile ) {
        if ( $poolCntFile =~ /^[\da-f]{16,}$/i ) {
            #
            # Print a specific digest count instead
            #
            $digest      = pack("H*", $poolCntFile);
            $poolCntFile = sprintf("%s/%02x/poolCnt",
                $Conf{CompressLevel} ? $bpc->{CPoolDir} : $bpc->{PoolDir},
                vec($digest, 0, 8) & 0xfe);
        }
        if ( !-f $poolCntFile ) {
            print STDERR "$poolCntFile does not exist\n";
            exit(1);
        }
    }

    my $count = BackupPC::XS::PoolRefCnt::new();

    if ( $count->read($poolCntFile) ) {
        print("Can't read ref count file $poolCntFile\n");
        exit(1);
    }
    print("Pool Ref Count file $poolCntFile:\n");
    my $idx = 0;
    my($d, $c);
    while ( 1 ) {
        ($d, $c, $idx) = $count->iterate($idx);
        last if ( !defined($d) );
        next if ( defined($digest) && $d ne $digest );
        printf("    %-20s => %d\n", unpack("H*", $d), $c);
    }
}