453302dd8926e2280b3ce82e5d65843ee3096c96
[rersyncrecent.git] / bin / rrr-client
blob453302dd8926e2280b3ce82e5d65843ee3096c96
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 =back
64 =head1 DESCRIPTION
66 After you have setup a tree watch it with inotify and keep it
67 uptodate. Depends on inotify which probably only exists on linux.
69 =cut
71 our %Opt;
72 GetOptions
73 (\%Opt,
74 @opt,
75 ) or pod2usage(1);
77 if ($Opt{help}) {
78 pod2usage(0);
80 pod2usage(1) unless $Opt{source} and $Opt{target};
82 $ENV{RSYNC_PASSWORD} = $Opt{password} if $Opt{password};
83 $Opt{verbose} ||= 0;
84 $Opt{"skip-deletes"} ||=0;
86 use File::Rsync::Mirror::Recent;
87 my $rrr = File::Rsync::Mirror::Recent->new
89 ignore_link_stat_errors => 1,
90 localroot => $Opt{target},
91 ($Opt{tmpdir} ? (tempdir => $Opt{tmpdir}) : ()),
92 remote => ($Opt{user} ? $Opt{user} . '@' : '') . $Opt{source},
93 max_files_per_connection => 20000,
94 rsync_options => {
95 compress => 1,
96 links => 1,
97 'safe-links' => 1,
98 times => 1,
99 checksum => 0,
100 timeout => 30, # do not allow rsync to hang for too long
101 ($Opt{tmpdir} ? ('temp-dir' => $Opt{tmpdir}) : ()),
103 verbose => $Opt{verbose},
104 _runstatusfile => "recent-rmirror-state.yml",
105 # _logfilefordone => "recent-rmirror-donelog.log",
108 $rrr->rmirror ( "skip-deletes" => $Opt{"skip-deletes"}, loop => 1 );