additional talk about the protocol and its relation to bittorrent
[rersyncrecent.git] / HOWTO.mirrorcpan
blobcd145ca73acf505342fc045a4909eb2671e64795
1 #!perl
3 =head1 HOW TO MIRROR CPAN
5 As of this writing the single purpose for this distribution is to
6 provide a backbone for the CPAN.
8 The idea is to get a handful backbone nodes that mirror directly from
9 PAUSE and a second layer that mirrors from them. Targetting at a
10 mirroring interval of 20 seconds.
12 The rsync daemon on PAUSE runs on port 8732 and you need a password to
13 access it. There is a second rsync daemon running on the standard port
14 873 but it has very limited access policies to leave the bandwidth for
15 the backbone.
17 If you have username and password you can mirror directly from PAUSE.
18 If you haven't and maintain a public CPAN mirror, ask me for one.
19 Otherwise pick your best CPAN mirror with an rsync server and try the
20 same script below for getting the quickest update cycle possible.
22 You find a list of potential rsync servers at
23 http://cpan.perl.org/SITES.html#RSYNC
25 The first thing you should prepare is the CPAN tree itself on your
26 disk. The source where you take it from does not matter that much.
27 Take it from where you always took it. The setup I suggest is to
28 mirror authors/ and modules/ with this program. And once per day or
29 per week or so do a traditional rsync from that old school mirroring
30 host, maybe excluding authors/ and modules/.
32 The loop is something like this:
34     $ENV{USER}="sandy"; # fill in your name
35     $ENV{RSYNC_PASSWORD} = "secret"; # fill in you passwd
37     use File::Rsync::Mirror::Recent;
38     my @rrr = map {
39         File::Rsync::Mirror::Recent->new
40                 (
41                  ignore_link_stat_errors    => 1,
42                  localroot                  => "/home/ftp/pub/PAUSE/$_", # your local path
43                  remote                     => "pause.perl.org::PAUSE/$_/RECENT.recent", # your upstream
44                  max_files_per_connection   => 863,
45                  tempdir                    => "/home/ftp/tmp", # optional tempdir to hide temporary files
46                  ttl                        => 10,
47                  rsync_options              =>
48                  {
49                   port              => 8732, # only for PAUSE
50                   compress          => 1,
51                   links             => 1,
52                   times             => 1,
53                   checksum          => 0,
54                   'omit-dir-times'  => 1, # not available before rsync 3.0.3
55                  },
56                  verbose                    => 1,
57                 )} "authors", "modules";
58     die "directory $_ doesn't exist, giving up" for grep { ! -d $_->localroot } @rrr;
59     while (){
60         my $ttgo = time + 1200; # pick less if you have a password and/or consent from the upstream
61         for my $rrr (@rrr){
62             $rrr->rmirror ( "skip-deletes" => 1 );
63         }
64         my $sleep = $ttgo - time;
65         if ($sleep >= 1) {
66             print STDERR "sleeping $sleep ... ";
67             sleep $sleep;
68         }
69     }
71 =pod
73 Don't forget to fill in your user name and password.
75 You see the 'skip-deletes' and guess, this is mirroring without doing
76 deletes. You can do it with deletes or you can leave the deletion to
77 the other, the traditional rsync loop. Worry about that later.
79 You see the option 'max_files_per_connection' which I filled with 863
80 and you need to find your favorite number. The larger the number the
81 faster the whole download goes. As you already have a mirror, you
82 probably want to take 10 or 20 times times that much. CPAN is at the
83 moment (2009-03) consisting of 142000 files. This option chunks the
84 downloads into piecemeal units and between these units the process
85 takes a peek at the most recent files to download them with higher
86 preference.
88 The localroot parameter contains your target directory. Because only
89 the authors/ and the modules/ directory are hosted by the PAUSE, you
90 need the loop over two directories. The other directories of CPAN are
91 currently not available for downloading with
92 File::Rsync::Mirror::Recent.
94 The 'port' is only needed for users who have a password for PAUSE,
95 other rsync servers listen on the rsync server port and the option can
96 be omitted.
98 The timeslice in the while loop above needs to be large enough to let
99 the rsync server survive. If you choose a random rsync server and are
100 not an rsync server yourself please be modest and choose 1200. Choose
101 less if you're offering rsync yourself and have a fat pipe, and
102 especially if you know your upstream can manage it. If you have a
103 PAUSE password choose 20 seconds. We will watch how well this works
104 and will adjust this recommendation according to our findings.
106 Set the key 'verbose' to 0 if you have no debugging demands. In this
107 case you want to omit the 'sleeping $sleep ...' noise further down the
108 script as well.
110 You can leave everything else as it stands. Start experimenting and
111 let me know how it works out.
113 -- 
114 andreas koenig
116 =cut