2

I'm trying to configure apt-mirror, it's working fine for ubuntu upstreams but when I use it for something like GitLab, it downloads all package versions.

For example, gitlab-ce is 72GB, each version is under 300MB. How can I keep just the latest or even the last 1 or 2 packages, not 459?

1 Answer 1

5
+50

APT Mirror is intended to mirror the whole repository from mirror.list entries only.

In a few sentences apt-mirror works like this:

  1. Gets index files from the repository and processes them (the same process as apt update).

  2. Downloads files from collected index files, if they do not exist locally. The folder structure is preserved in this process (similar to wget -c -x <url_file_array>).

For more detailed information about how apt-mirror works and for confirming that it is impossible to partially mirror the repository to get latest versions only, you can refer to The Source code of apt-mirror (Written in Perl).

So, what to do to get latest versions from large repositories?

My temporary workaround for your situation (taking for example, gitlab-ce repository for Ubuntu 18.04 - Bionic):

  1. Enter the path for mirroring:

    cd /path/to/mirroring
    
  2. Backup sources.list:

    sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
    
  3. Open and comment every line in sources.list:

    sudo nano /etc/apt/sources.list
    
  4. Add your desired repository(ies) for mirroring:

    4.1. Add this to sources.list and exit from the file: deb https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/ bionic main

    4.2. Add the GPG:

    curl -L https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey | sudo apt-key add -
    
  5. Update index files:

    sudo apt update
    
  6. Fetch latest packages url from added repository and write them to file:

    sudo apt-get install '*' --allow-unauthenticated -y --print-uris | grep -o '\'http.*\' | tr "\'" " " > download-list
    
  7. Download the urls with folder structure, because of -c option, it will not download files that exist:

    wget -i download-list -c -x
    

    Enjoy!!!

    For reverting everything back, just replace the sources.list file with old sources.list.bak and do:

    sudo apt update
    

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .