1#!/usr/bin/perl
2
3=head1 NAME
4
5mogrename -- Rename file (key) from one key to another
6
7=head1 SYNOPSIS
8
9    $ mogrename [OPTIONS] --old_key='/hello.jpg' --new_key='/bye.jpg'
10
11    $ mogupload --trackers=host --domain=foo --class=bar \
12                --old_key='/hello.jpg' --new_key='/bye.jpg'
13
14    $ mogupload --trackers=host1:7001,host2:7001 --domain=foo --class=bar \
15                --old_key='/hello.jpg' --new_key='/bye.jpg'
16
17=head1 OPTIONS
18
19=over
20
21=item --trackers=host1:7001,host2:7001
22
23Use these MogileFS trackers to negotiate with.
24
25=item --domain=<domain>
26
27Set the MogileFS domain to use.
28
29=item --class=<class>
30
31Set the class to use. Will use default class if not specified.
32
33=item --old_key='<old key>'
34
35An old key to rename the file from. Can be an arbitrary string.
36
37=item --new_key='<new key>'
38
39A new key to rename the file to. Can be an arbitrary string.
40
41=back
42
43=head1 AUTHOR
44
45Krzysztof Wilczynski E<lt>L<krzysztof.wilczynski@linux.com>E<gt>
46
47=head1 BUGS
48
49None for this release. Please report any issues found.
50
51=head1 LICENSE
52
53Licensed for use and redistribution under the same terms as Perl itself.
54
55=cut
56
57use strict;
58use warnings;
59
60use lib './lib';
61use MogileFS::Utils;
62
63my $utils = MogileFS::Utils->new;
64
65my $usage = "--trackers=host --domain=foo --class=bar "
66          . "--old_key='/hello.jpg' --new_key='/bye.jpg'";
67
68my $options = $utils->getopts($usage, qw(old_key=s new_key=s));
69
70my $mogile_client = $utils->client;
71
72$mogile_client->rename($options->{'old_key'}, $options->{'new_key'});
73
74if ($mogile_client->errcode) {
75    die "Error renaming file (key) from " . $mogile_client->errstr;
76}
77