5 moglistfids -- Iterate fid/key data from a MogileFS installation
9 Example utility for pulling all file data out of a MogileFS installation.
10 Utilities like this can be built on for creating backup systems,
11 Mogile<->Mogile syncronization systems, or Mogile->S3 syncronization.
13 This method is only a way of pulling new files which have existed since the
14 last time it was checked, as there's no logging of deleted files.
20 =item --trackers=host1:7001,host2:7001
22 Use these MogileFS trackers to negotiate with.
26 The highest numbered fid fetched the last time this utility was run.
30 Numer of fids to inspect and return.
36 Dormando E<lt>L<dormando@rydia.net>E<gt>
44 Licensed for use and redistribution under the same terms as Perl itself.
55 my $util = MogileFS
::Utils
->new;
56 my $usage = "--trackers=host --fromfid=123 --count=5000";
57 my $c = $util->getopts($usage, qw
/fromfid=i count=i/);
59 my $moga = MogileFS
::Admin
->new(hosts
=> $c->{trackers
});
61 my $fromfid = $c->{fromfid
} || 0;
62 my $count = $c->{count
} || 100;
65 # Try to fetch the max, but we will likely get less.
66 my $fids_chunk = $moga->list_fids($fromfid, $count);
68 die "Error listing fids: ", $moga->errstr, "\n";
70 my @fids = sort { $a <=> $b } keys %$fids_chunk;
75 my $file = $fids_chunk->{$fid};
76 print "fid ", $fid, "\n";
77 for my $key (sort keys %$file) {
78 my $val = $file->{$key};
79 $val = _escape_url_string
($val) if $key eq 'dkey';
80 print $key, " ", $val, "\n";
86 sub _escape_url_string
{
88 $str =~ s/([^a-zA-Z0-9_\,\-.\/\\\: ])/uc sprintf("%%%02x",ord($1))/eg
;