--- a/bin/imager Thu Aug 25 22:12:14 2011 +0200
+++ b/bin/imager Wed Sep 07 19:38:02 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<imager
compress --help> for more information.
+=item list
+
+List the backups/images available. See C<imager list --help> for more information.
+
=back
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/imager.list Wed Sep 07 19:38:02 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<imager.list> 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