# HG changeset patch # User Heiko Schlittermann (JUMPER) # Date 1315603787 -7200 # Node ID ae622a73b077ea22f991831b7f5070beb6a70988 # Parent 05a15016658f57408e670389bf9d8d22e1925e16# Parent 8397c7a3e5b174d95a4755328bf69e7716d9c43a =merged diff -r 05a15016658f -r ae622a73b077 bin/imager --- a/bin/imager Fri Sep 09 23:25:03 2011 +0200 +++ b/bin/imager Fri Sep 09 23:29:47 2011 +0200 @@ -16,7 +16,7 @@ ); }, ) - and $ARGV[0] ~~ [qw(save restore fuse check compress)] + and $ARGV[0] ~~ [qw(save restore fuse check compress list)] or pod2usage; exec "$0." . shift() => @ARGV; @@ -72,9 +72,13 @@ =item compress -Check the compression and decompress or compress. See C<--imager +Check the compression and decompress or compress. See C for more information. +=item list + +List the backups/images available. See C for more information. + =back diff -r 05a15016658f -r ae622a73b077 bin/imager.list --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/imager.list Fri Sep 09 23:29:47 2011 +0200 @@ -0,0 +1,94 @@ +#! /usr/bin/perl + +use 5.010; +use strict; +use warnings; +use Pod::Usage; +use Hash::Util qw(lock_keys); +use File::Find; +use Digest::MD5 qw(md5_hex); +use File::Basename; +use autodie qw(:all); +use Imager; + +use Getopt::Long; + +our %o = ( + latest => undef, +); +lock_keys(%o); + +MAIN: { + my $dir; + + Getopt::Long::Configure qw(Bundling); + GetOptions( + "latest" => \$o{latest}, + "h|help" => sub { pod2usage(-verbose => 1, -exit => 0) }, + "m|man" => sub { + pod2usage( + -verbose => 2, + -exit => 0, + -noperldoc => system( + "perldoc -V 1>/dev/null + 2>&1" + ) + ); + }, + ) + and defined ($dir = shift) + or pod2usage; + + my (%by_day, %by_dev); + find(sub{ + return if not (-f and /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ$/); + my ($host, $dev) = dirname($File::Find::name) =~ /^\Q$dir\/idx\E\/(.+?)(\/.*)/; + push @{$by_day{$_}}, "$host\::$dev"; + push @{$by_dev{"$host\::$dev"}}, $_; + }, "$dir/idx"); + + # by dev + my $l = (sort { $b <=> $a } map { length } keys %by_dev)[0]; + foreach (sort keys %by_dev) { + my $prefix = $_; + foreach ((reverse sort @{$by_dev{$_}})) { + printf "%-*s: %s\n", $l => $prefix, $_; + last if $o{latest}; + $prefix = " "; + } + } + +} + +__END__ + +=head1 NAME + + imager.list - list the images created by imager + +=head1 SYNOPSIS + + imager.list [options] {directory} + +=head1 DESCRIPTION + +B lists the index files (images) the imager created. + + +=head1 OPTIONS + +=over + +=item B<--latest> + +List only the latest backups. (default: list all) + +=item B<-h>|B<--help> + +=item B<-m>|B<--man> + +The short and longer help. + +=back + +=cut