Skip to content

Commit

Permalink
Add "mogrename" utility script.
Browse files Browse the repository at this point in the history
Adding simple mogrename utility script that allows for renaming file (key)
form an old key to a new key easily.

Signed-off-by: Krzysztof Wilczynski <[email protected]>
  • Loading branch information
kwilczynski authored and dormando committed Jan 15, 2012
1 parent 93c53d7 commit 8d1c1ae
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Changes
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
2.21 -- 2011-12-16

* Add "mogrename" utility script (kwilczynski, Krzysztof Wilczynski).

2.21 -- 2011-10-29

* Improve error handling for broken usage files in `mogadm check`

2.20 -- 2011-06-15

* Remove redundant tracker calls. Required for MogileFS::Server 2.50 as
the redundant commands are now cached harder.
the redundant commands are now cached harder.
(dormando <[email protected]>)

2.19 -- 2011-01-08
Expand Down
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ mogfileinfo
moglistfids
moglistkeys
mogfiledebug
mogrename
2 changes: 1 addition & 1 deletion Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ WriteMakefile(
ABSTRACT => 'MogileFS utilities',
EXE_FILES => ['mogtool', 'mogadm', 'mogstats',
'mogupload', 'mogfetch', 'mogdelete', 'mogfileinfo', 'moglistkeys',
'moglistfids', 'mogfiledebug',
'moglistfids', 'mogfiledebug', 'mogrename',
],
PREREQ_PM => {
'LWP::Simple' => 0,
Expand Down
76 changes: 76 additions & 0 deletions mogrename
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/perl

=head1 NAME
mogrename -- Rename file (key) from one key to another
=head1 SYNOPSIS
$ mogrename [OPTIONS] --old-key='/hello.jpg' --new-key='/bye.jpg'
$ mogupload --trackers=host --domain=foo --class=bar \
--old-key='/hello.jpg' --new-key='/bye.jpg'
$ mogupload --trackers=host1:7001,host2:7001 --domain=foo --class=bar \
--old-key='/hello.jpg' --new-key='/bye.jpg'
=head1 OPTIONS
=over
=item --trackers=host1:7001,host2:7001
Use these MogileFS trackers to negotiate with.
=item --domain=<domain>
Set the MogileFS domain to use.
=item --class=<class>
Set the class to use. Will use default class if not specified.
=item --old-key='<old key>'
An old key to rename the file from. Can be an arbitrary string.
=item --new-key='<new key>'
A new key to rename the file to. Can be an arbitrary string.
=back
=head1 AUTHOR
Krzysztof Wilczynski E<lt>L<[email protected]>E<gt>
=head1 BUGS
None for this release. Please report any issues found.
=head1 LICENSE
Licensed for use and redistribution under the same terms as Perl itself.
=cut

use strict;
use warnings;

use lib './lib';
use MogileFS::Utils;

my $utils = MogileFS::Utils->new;

my $usage = "--trackers=host --domain=foo --class=bar "
. "--old-key='/hello.jpg' --new-key='/bye.jpg'";

my $options = $utils->getopts($usage, qw(old-key=s new-key=s));

my $mogile_client = $utils->client;

$mogile_client->rename($options->{'old-key'}, $options->{'new-key'});

if ($mogile_client->errcode) {
die "Error renaming file (key) from " . $mogile_client->errstr;
}

0 comments on commit 8d1c1ae

Please sign in to comment.