6.38 Maintaining an Archive

Downloaded Debian packages are placed into /var/cache/apt/archive. You can have the files moved into a local hierarchy that mirrors a standard Debian distribution hierarchy. Then you can point the /etc/apt/sources.list to this local archive by using the file:// format.

To set up a local machine as a local (partial) mirror of the Debian archive, wajig will use the apt-move package.

Edit /etc/apt-move.conf to set the DIST to match your system (default is stable):

  DIST=unstable

The wajig command move will then move any packages in your /var/cache/apt/archives into the Debian mirror being created (/mirrors/debian is created by default):

  $ wajig move

You can actually create a complete mirror with:

  # apt-move mirror

These commands place the packages into /mirrors/debian. To make it available on your web server simply:

  # cd /var/www
  # ln -s /mirrors pub

The file /etc/apt/sources.list can then be updated to point to the new archive as the first place to check for packages (place this lines first in the file):

  deb http://athens/pub/debian unstable main contrib non-free

All of this might happen on your server (called athens in this example) and other machines on your local network can then access the local archive by adding the above line to /etc/apt/sources.list.

If your server is not the most up to date machine (since you may not want to run the risk of your server becoming unstable), you can rsync all packages in /var/cache/apt/archives on other machines to the server and then run the move command on the server:

  # rsync -vr friend:/var/cache/apt/archives/ /var/cache/apt/archives/
  # ssh friend wajig clean         (apt-get clean)
  # wajig move                     (apt-move update)

In fact, on your server you could use the following Python script saved to file /root/apt-archive.py to automate this for each of the hosts on the network:

#!/usr/bin/env python
import os

hosts = ['friend', 'cargo']
archive = '/var/cache/apt/archives/'

for h in hosts:
    os.system('rsync -vr %s:%s %s' % (h, archive, archive))
    os.system('ssh %s wajig clean' % h)

os.system('wajig move')

Then set the script up to run:

  # chmod u+x apt-archive.py

and run it as required:

  # ./apt-archive.py

Depending on how you have ssh set up this may ask for your password for each connection. To avoid this, you can use public/private keys with no passphrase (see Section @ref(ssh.public.keys)), and then the script could be run automatically using crontab each morning by copying the executable script to /etc/cron.daily/apt-archive. Note that scripts in /etc/cron.daily with a py extension are not run, so be sure to rename the file as suggested here.



Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0