5 mogfetch -- Fetch data from a MogileFS installation
10 $ mogfetch [options] --file="-" > filename
12 $ mogfetch --trackers=host --domain=foo \
13 --key="/hello.jpg" --file="output.jpg"
19 =item --trackers=host1:7001,host2:7001
21 Use these MogileFS trackers to negotiate with.
23 =item --domain=<domain>
25 Set the MogileFS domain to use.
29 The key to locate the data with. Can be an arbitrary string.
31 =item --file="<filename|->"
33 A local destination file. If '-', data is written to STDOUT instead.
39 Dormando E<lt>L<dormando@rydia.net>E<gt>
47 Licensed for use and redistribution under the same terms as Perl itself.
57 my $util = MogileFS
::Utils
->new;
58 my $usage = "--trackers=host --domain=foo --key='/hello.jpg' --file='./output'";
59 my $c = $util->getopts($usage, qw
/key=s file=s/);
61 my $mogc = $util->client;
63 # Default to noverify, don't hang up the tracker. We'll try all paths.
64 my @paths = $mogc->get_paths($c->{key
}, { noverify
=> 1 });
66 die "Error fetching paths: " . $mogc->errstr;
69 die "No paths found or key does not exist" unless @paths;
71 my $filename = $c->{file
};
73 for my $path (@paths) {
74 next unless $path; # overparanoid?
75 my $ua = LWP
::UserAgent
->new;
79 if ($filename eq '-') {
82 open($file, "> $filename") or die "Could not open " . $filename;
88 my $res = $ua->get($path, ':content_cb' => $writeout,
89 ':read_size_hint' => 32768);
91 if ($res->is_success) {
94 # print all the errors to be the most helpful
101 for my $res (@resses) {
102 print STDERR
"Got errors while trying to fetch:\n";
103 print STDERR
$res->status_line, "\n";