Permalink
Browse files

Add "mogrename" utility script.

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 <krzysztof.wilczynski@linux.com>
  • Loading branch information...
1 parent 93c53d7 commit 8d1c1aeb7fb22ddda30895dd9a203bb7d895ce79 @kwilczynski kwilczynski committed with dormando Dec 16, 2011
Showing with 83 additions and 2 deletions.
  1. +5 −1 Changes
  2. +1 −0 MANIFEST
  3. +1 −1 Makefile.PL
  4. +76 −0 mogrename
View
@@ -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 <dormando@rydia.net>)
2.19 -- 2011-01-08
View
@@ -13,3 +13,4 @@ mogfileinfo
moglistfids
moglistkeys
mogfiledebug
+mogrename
View
@@ -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,
View
@@ -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<krzysztof.wilczynski@linux.com>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.