add rsync timeout option
[rersyncrecent.git] / bin / rrr-client
blobd4d3f69d5d1dbee30c607b1d2a861d7d56a43d17
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<--tmpdir=s>
49 Directory for temporary files; should be on the same file system
50 partition as the C<--target> directory.
52 =back
54 =head1 DESCRIPTION
56 After you have setup a tree watch it with inotify and keep it
57 uptodate. Depends on inotify which probably only exists on linux.
59 =cut
61 our %Opt;
62 GetOptions
63 (\%Opt,
64 @opt,
65 ) or pod2usage(1);
67 if ($Opt{help}) {
68 pod2usage(0);
70 pod2usage(1) unless $Opt{source} and $Opt{target};
72 $ENV{RSYNC_PASSWORD} = $Opt{password} if $Opt{password};
74 use File::Rsync::Mirror::Recent;
75 my $rrr = File::Rsync::Mirror::Recent->new
77 ignore_link_stat_errors => 1,
78 localroot => $Opt{target},
79 ($Opt{tmpdir} ? (tempdir => $Opt{tmpdir}) : ()),
80 remote => ($Opt{user} ? $Opt{user} . '@' : '') . $Opt{source},
81 max_files_per_connection => 20000,
82 rsync_options => {
83 compress => 1,
84 links => 1,
85 'safe-links' => 1,
86 times => 1,
87 checksum => 0,
88 timeout => 300, # do not allow rsync to hang forever
89 ($Opt{tmpdir} ? ('temp-dir' => $Opt{tmpdir}) : ()),
91 verbose => 1,
92 _runstatusfile => "recent-rmirror-state.yml",
93 # _logfilefordone => "recent-rmirror-donelog.log",
96 $rrr->rmirror ( "skip-deletes" => 0, loop => 1 );