Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Set Up A Debian Mirror Using Rsync

When apt-mirror has problems, one can always fall back to the good old days of setting up mirrors using rsync.

Related Posts


Firstly, we need to set install apache and a storage path. The storage path should have over 1 TiB of space.

sudo apt install apache2 -y

sudo mkdir -p $STORAGE_PATH
sudo ln -s $STORAGE_PATH /var/www/debian

Configure Apache

Run the following command to configure apache.

sudo echo '<VirtualHost *:80>

    DocumentRoot /var/www
        <Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>' | sudo tee /etc/apache2/sites-enabled/000-default.conf

Now we need to create a user that will be executing the sync, yet the webserver can access all the files of. It's nice to be able to log in as this user to manually run the sync from time to time.

sudo adduser $MIRROR_USER
sudo adduser www-data $MIRROR_USER

Now switch to that user and go to the home directory.

cd $HOME

Create and execute the following script. I called it which will be referenced later in a cron.



rsync \
  --recursive \
  --links \
  --perms \
  --times \
  --compress \
  --progress \
  --delete \
  rsync:// \

You can add --bwlimit=1000 to limit the bandwidth to 1000 Kilobytes per second. You will need to do the math to convert from kilobytes to Megabits.


Now we need the mirror to automatically stay up to date. We will run the task at midnight.

Make sure you only do this after you have completed the initial sync which will likely take many hours.

If you haven't already, log in as your mirror user:


Edit the crontab file for that user.

crontab -e

Add the following line:

0 0 * * * $HOME/

Use Your Mirror

You can now configure your Debian computers to use this mirror for updates.


Last updated: 17th April 2021
First published: 17th April 2021