Creating an official Debian mirror with apt-mirror, debmirror or ftpsync

In this article I'll demonstrate 3 ways of creating a local Debian mirror using the apt-mirror, debmirror and the ftpsync tools. I'll be mirroring Debian Wheezy, which will download about 79GB of packages. If your environment consists of many server builds each day, having a local Debian mirror will save you time and bandwidth.

I'll be using a Debian Wheezy server for this purpose.

First install the apt-mirror package and apache:

The apt-mirror config file is /etc/apt/mirror.list and should contain the following:

You can put whatever mirror is closer to you and  add or remove different repository sections. In this example I am interested in mirroring the main, contrib and the non-free sections.

Now that the config is there just run:

This will have the packages downloaded to

Let's expose the repo over HTTP:

And use it:

In some cases you might need to have a stable section in your repo. In this case you can just create a symlink to Wheezy:

To keep the repository in sync with the upstream Debian you can create a cronjob that pulls new packages at midnight:


Alternatively you can mirror any repo e.g. Percona using debmirror with this one liner:

The recommended way of mirroring Debian repository is by using the ftpsync mirroring tool [1].

Let's install it and configure it to mirror wheezy and squeesze:

The config file should at a minimum look like this (if you only want to mirror i386 and amd64 architectures):

With all that in place time to rsync the files:

Or if you rather run the two rsync stages one at a time, execute:

This really just runs these two rsync commands one after the other:

To mirror the OpenVZ repo at download.openvz.org first let's find what rsync shares are supported:

After some trial and error the openvz-download is the share that works. The config file should look like so:

To rsync the repo run:
Notice how the config file has the OPENVZ name in it and how we specify which config to run by passing the sync:archive:OPENVZ parameters to the ftpsync script.

Resources:
[1]. http://ftp-master.debian.org/ftpsync.tar.gz