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