af5a17805ab70b272e006b1a7cc8fd3045124023
[rersyncrecent.git] / bin / rrr-client
blobaf5a17805ab70b272e006b1a7cc8fd3045124023
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use Getopt::Long;
5 use Pod::Usage qw(pod2usage);
7 =head1 NAME
9 rrr-client - continously mirror recent updates
11 =head1 SYNOPSIS
13 rrr-client [options]
15 rrr-client --source some.mirror::module/ --target /some/dir/
17 =head1 OPTIONS
19 =over 8
21 =cut
23 my @opt = <<'=back' =~ /B<--(\S+)>/g;
25 =item B<--help|h>
27 Prints a brief message and exists.
29 =item B<--source=s>
31 Source to mirror from, including the name of the RECENT metadata file.
32 For example C<cpan-rsync.perl.org::CPAN/RECENT.recent>.
34 =item B<--target=s>
36 Destination directory for the mirror.
38 =item B<--user=s>
40 Username if the rsync source requires it.
42 =item B<--password=s>
44 Password if the rsync source requires it. Can also be set by setting
45 the environment variable RSYNC_PASSWORD.
47 =item B<--skip-deletes!>
49 Defaults to false. If true, skips all delete events in the index files
50 which means no files are being deleted that have been deleted upstream.
52 =item B<--tmpdir=s>
54 Directory for temporary files; should be on the same file system
55 partition as the C<--target> directory.
57 =item B<--verbose!>
59 Defaults to false. Note: Older versions of rrr-client defaulted to
60 being verbose.
62 =item B<--verboselog=s>
64 Path to the logfile to write verbose progress information to.
66 =back
68 =head1 DESCRIPTION
70 Mirror a remote directory based on a set of RECENT* files provided by
71 the remote server.
73 =cut
75 our %Opt;
76 GetOptions
77 (\%Opt,
78 @opt,
79 ) or pod2usage(1);
81 if ($Opt{help}) {
82 pod2usage(0);
84 pod2usage(1) unless $Opt{source} and $Opt{target};
86 $ENV{RSYNC_PASSWORD} = $Opt{password} if $Opt{password};
87 $Opt{verbose} ||= 0;
88 $Opt{"skip-deletes"} ||=0;
90 use File::Rsync::Mirror::Recent;
91 my $rrr = File::Rsync::Mirror::Recent->new
93 ignore_link_stat_errors => 1,
94 localroot => $Opt{target},
95 ($Opt{tmpdir} ? (tempdir => $Opt{tmpdir}) : ()),
96 remote => ($Opt{user} ? $Opt{user} . '@' : '') . $Opt{source},
97 max_files_per_connection => 20000,
98 rsync_options => {
99 compress => 1,
100 links => 1,
101 'safe-links' => 1,
102 times => 1,
103 checksum => 0,
104 timeout => 30, # do not allow rsync to hang for too long
105 ($Opt{tmpdir} ? ('temp-dir' => $Opt{tmpdir}) : ()),
107 verbose => $Opt{verbose},
108 ($Opt{verboselog} ? (verboselog => $Opt{verboselog}) : ()),
109 _runstatusfile => "recent-rmirror-state.yml",
110 # _logfilefordone => "recent-rmirror-donelog.log",
113 $rrr->rmirror ( "skip-deletes" => $Opt{"skip-deletes"}, loop => 1 );