Checking in changes prior to tagging of version 2.30.
[MogileFS-Utils.git] / moglistkeys
blob40f1fdb3b5fecf67225708466ebe30f497ef8dbd
1 #!/usr/bin/perl
3 =head1 NAME
5 moglistkeys -- Lists keys out of a MogileFS domain
7 =head1 SYNOPSIS
9 $ moglistkeys --trackers=host --domain=foo --key_prefix="/foo/bar/"
11 =head1 DESCRIPTION
13 If you store your MogileFS keys in a logical "structure", you may use this
14 tool to view lists of subsets of keys. Note that this is not going to be
15 equivalent to "cd" and "ls" tools, as listing "foo/" will list everything
16 underneath, so it's more akin to "ls -R"
18 =head1 OPTIONS
20 =over
22 =item --trackers=host1:7001,host2:7001
24 Use these MogileFS trackers to negotiate with.
26 =item --domain=<domain>
28 Set the MogileFS domain to use.
30 =item --key_prefix="/foo/bar/"
32 Search for keys starting with this prefix. Can be an arbitrary string.
34 =back
36 =head1 AUTHOR
38 Dormando E<lt>L<dormando@rydia.net>E<gt>
40 =head1 BUGS
42 None known.
44 =head1 LICENSE
46 Licensed for use and redistribution under the same terms as Perl itself.
48 =cut
50 # TODO: Add ways to limit # of keys displayed
52 use strict;
53 use warnings;
55 use lib './lib';
56 use MogileFS::Utils;
58 my $util = MogileFS::Utils->new;
59 my $usage = "--trackers=host --domain=foo --key_prefix='bar/'";
60 my $c = $util->getopts($usage, 'key_prefix=s');
62 my $mogc = $util->client;
64 $mogc->foreach_key(prefix => $c->{key_prefix}, sub {
65 my $key = shift;
66 print $key, "\n";
67 });
69 if ($mogc->errcode) {
70 die "Error listing files: ", $mogc->errstr, "\n";