remove the dated references to pause as upstream, bring a few aspects that were missi...
[rersyncrecent.git] / HOWTO.mirrorcpan
blob74eaa274ac4472e92f64b20346875d2e7b0ab30e
1 #!perl
3 =head1 HOW TO MIRROR CPAN
5 As of this writing the single purpose for this distribution is to
6 provide a fast rsync client/server combination for the CPAN.
8 You find a list of potential rsync servers at
9 http://cpan.perl.org/SITES.html
11 Find current stats at http://mirror.cpan.org/
13 The first thing you should prepare is the CPAN tree itself on your
14 disk. The source where you take it from does not matter that much.
15 Take it from where you always took it.
17 The loop is something like this:
19 Short version:
21     #!/bin/sh
23     rrr-client --source rsync://cpan-rsync.perl.org::CPAN --target /home/rrrcpan/target --tmpdir /home/tmp &
25 Or if the short version is not sufficient for some reason, maybe you
26 want only the authors/ and modules/ tree:
28     use File::Rsync::Mirror::Recent;
29     my @rrr = map {
30         File::Rsync::Mirror::Recent->new
31                 (
32                  localroot                  => "/home/rrrcpan/target/$_", # your local path
33                  remote                     => "cpan-rsync.perl.org::CPAN/$_/RECENT.recent", # your upstream
34                  max_files_per_connection   => 863, # arbitrary
35                  tempdir                    => "/home/ftp/tmp", # optional tempdir to hide temporary files
36                  ttl                        => 10,
37                  rsync_options              =>
38                  {
39                   compress          => 1,
40                   links             => 1,
41                   times             => 1,
42                   checksum          => 0,
43                   'omit-dir-times'  => 1, # not available before rsync 3.0.3
44                   timeout           => 300, # do not allow rsync to hang forever
45                  },
46                  tmpdir                     => "/home/rrrcpan/target",
47                  verbose                    => 1,
48                  verboselog                 => "/var/log/rmirror-pause.log",
49                 )} "authors", "modules";
50     die "directory $_ doesn't exist, giving up" for grep { ! -d $_->localroot } @rrr;
51     while (){
52         my $ttgo = time + 1200; # arbitrary
53         for my $rrr (@rrr){
54             $rrr->rmirror ( "skip-deletes" => 1 );
55         }
56         my $sleep = $ttgo - time;
57         if ($sleep >= 1) {
58             print STDERR "sleeping $sleep ... ";
59             sleep $sleep;
60         }
61     }
63 =pod
65 Target directory is, of course, your choice, so replace
66 '/home/rrrcpan/target' with your favorite path.
68 The tmpdir is important and must reside on the same partition as the
69 target directory, so that rename(2) works.
71 You see the 'skip-deletes' and guess, this is mirroring without doing
72 deletes. You can do it with deletes or you can leave the deletion to
73 the other, the traditional rsync loop. Worry about that later.
75 You see the option 'max_files_per_connection' which I filled with 863
76 and you need to find your favorite number. The larger the number the
77 faster the whole download goes. As you already have a mirror, you
78 probably want to take 10 or 20 times times that much. CPAN's authors
79 directory is at the moment (2010-10) consisting of 180000 files. This
80 option chunks the downloads into piecemeal units and between these
81 units the process takes a peek at the most recent files to download
82 them with higher preference. That way we get the newest files
83 immediately in sync while we are mirroring the long tail of old files.
85 The localroot parameter contains your target directory. Because only
86 the authors/ and the modules/ directory are hosted by the PAUSE, you
87 need the loop over two directories. The other directories of CPAN are
88 currently not available for downloading with
89 File::Rsync::Mirror::Recent.
91 The timeslice in the while loop above needs to be large enough to let
92 the rsync server survive. If you choose a random rsync server and are
93 not an rsync server yourself please be modest and choose 1200. Choose
94 less if you're offering rsync yourself and have a fat pipe, and
95 especially if you know your upstream can manage it.
97 Set the key 'verbose' to 0 if you have no debugging demands. In this
98 case you want to omit the 'sleeping $sleep ...' noise further down the
99 script as well.
101 Set the key 'verboselog' to your favorite progress watcher file. This
102 option is underdeveloped and may later be replaced with something
103 better. Note that the program still sends error messages to STDERR.
105 You can leave everything else as it stands. Start experimenting and
106 let me know how it works out.
108 -- 
109 andreas koenig
111 =cut