Preview of a new lbs-util command for snapshot maintenance.
[cumulus.git] / lbs-util
1 #!/usr/bin/perl -w
2 #
3 # lbs-util: Tool for managing LBS archives.
4 #
5 # Usage: lbs-util <repository> <cmd> <args>
6 #
7 # Available commands:
8 #   --list-snapshots
9 #   --list-segments
10
11 use strict;
12 use LBS qw(parse_headers);
13
14 die "Too few arguments!\n" unless scalar(@ARGV) >= 2;
15 die "Must specify a repository!\n" unless -d $ARGV[0];
16
17 my $store = new LBS::Store $ARGV[0];
18 my $cmd = $ARGV[1];
19 my @args = @ARGV[2 .. $#ARGV];
20
21 if ($cmd eq "--list-snapshots") {
22     foreach ($store->list_snapshots()) {
23         print $_, "\n";
24     }
25 } elsif ($cmd eq "--list-segments") {
26     foreach ($store->list_segments()) {
27         print $_, "\n";
28     }
29 } elsif ($cmd eq "--verify-snapshot") {
30     my $snapshot = $store->load_snapshot($args[0]);
31     my %info = parse_headers($snapshot);
32     print "Root: $info{Root}\n";
33
34     my $metadata = new LBS::MetadataParser $store, $info{Root};
35     while ((my %item = $metadata->get_item())) {
36         print $item{name}, "\n";
37         if ($item{type} eq '-') {
38             my $size = 0;
39             my $verifier = new LBS::ChecksumVerifier $item{checksum};
40             foreach (split /\s+/, $item{data}) {
41                 my $data = $store->load_ref($_);
42                 $verifier->add($data);
43                 $size += length($data);
44             }
45             if (!$verifier->verify() || $size != $item{size}) {
46                 fprintf STDERR "Verification failure for $item{name}\n";
47             }
48         }
49     }
50 } else {
51     die "Unknown command: $cmd\n";
52 }