From 8d1c1aeb7fb22ddda30895dd9a203bb7d895ce79 Mon Sep 17 00:00:00 2001 From: Krzysztof Wilczynski Date: Fri, 16 Dec 2011 15:42:16 +0000 Subject: [PATCH] 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 --- Changes | 6 ++++- MANIFEST | 1 + Makefile.PL | 2 +- mogrename | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 mogrename diff --git a/Changes b/Changes index 779f35e..a38ef11 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,7 @@ +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` @@ -5,7 +9,7 @@ 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 ) 2.19 -- 2011-01-08 diff --git a/MANIFEST b/MANIFEST index 3d970e2..071935c 100644 --- a/MANIFEST +++ b/MANIFEST @@ -13,3 +13,4 @@ mogfileinfo moglistfids moglistkeys mogfiledebug +mogrename diff --git a/Makefile.PL b/Makefile.PL index 7021c72..320d50c 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -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, diff --git a/mogrename b/mogrename new file mode 100644 index 0000000..327f9bb --- /dev/null +++ b/mogrename @@ -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= + +Set the MogileFS domain to use. + +=item --class= + +Set the class to use. Will use default class if not specified. + +=item --old-key='' + +An old key to rename the file from. Can be an arbitrary string. + +=item --new-key='' + +A new key to rename the file to. Can be an arbitrary string. + +=back + +=head1 AUTHOR + +Krzysztof Wilczynski ELE + +=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; +}