equal
deleted
inserted
replaced
|
1 #! /usr/bin/perl |
|
2 |
|
3 use 5.010; |
|
4 use strict; |
|
5 use warnings; |
|
6 use Pod::Usage; |
|
7 use Hash::Util qw(lock_keys); |
|
8 use File::Find; |
|
9 use Digest::MD5 qw(md5_hex); |
|
10 use File::Basename; |
|
11 use autodie qw(:all); |
|
12 use Imager; |
|
13 |
|
14 use Getopt::Long; |
|
15 |
|
16 our %o = ( |
|
17 latest => undef, |
|
18 ); |
|
19 lock_keys(%o); |
|
20 |
|
21 MAIN: { |
|
22 my $dir; |
|
23 |
|
24 Getopt::Long::Configure qw(Bundling); |
|
25 GetOptions( |
|
26 "latest" => \$o{latest}, |
|
27 "h|help" => sub { pod2usage(-verbose => 1, -exit => 0) }, |
|
28 "m|man" => sub { |
|
29 pod2usage( |
|
30 -verbose => 2, |
|
31 -exit => 0, |
|
32 -noperldoc => system( |
|
33 "perldoc -V 1>/dev/null |
|
34 2>&1" |
|
35 ) |
|
36 ); |
|
37 }, |
|
38 ) |
|
39 and defined ($dir = shift) |
|
40 or pod2usage; |
|
41 |
|
42 my (%by_day, %by_dev); |
|
43 find(sub{ |
|
44 return if not (-f and /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ$/); |
|
45 my ($host, $dev) = dirname($File::Find::name) =~ /^\Q$dir\/idx\E\/(.+?)(\/.*)/; |
|
46 push @{$by_day{$_}}, "$host\::$dev"; |
|
47 push @{$by_dev{"$host\::$dev"}}, $_; |
|
48 }, "$dir/idx"); |
|
49 |
|
50 # by dev |
|
51 my $l = (sort { $b <=> $a } map { length } keys %by_dev)[0]; |
|
52 foreach (sort keys %by_dev) { |
|
53 my $prefix = $_; |
|
54 foreach ((reverse sort @{$by_dev{$_}})) { |
|
55 printf "%-*s: %s\n", $l => $prefix, $_; |
|
56 last if $o{latest}; |
|
57 $prefix = " "; |
|
58 } |
|
59 } |
|
60 |
|
61 } |
|
62 |
|
63 __END__ |
|
64 |
|
65 =head1 NAME |
|
66 |
|
67 imager.list - list the images created by imager |
|
68 |
|
69 =head1 SYNOPSIS |
|
70 |
|
71 imager.list [options] {directory} |
|
72 |
|
73 =head1 DESCRIPTION |
|
74 |
|
75 B<imager.list> lists the index files (images) the imager created. |
|
76 |
|
77 |
|
78 =head1 OPTIONS |
|
79 |
|
80 =over |
|
81 |
|
82 =item B<--latest> |
|
83 |
|
84 List only the latest backups. (default: list all) |
|
85 |
|
86 =item B<-h>|B<--help> |
|
87 |
|
88 =item B<-m>|B<--man> |
|
89 |
|
90 The short and longer help. |
|
91 |
|
92 =back |
|
93 |
|
94 =cut |