.. _mirroring-an-anaconda-repository:

================================
Mirroring an Anaconda repository
================================

NOTE: This documentation is for versions of Anaconda Repository 2.26 and newer. For versions between 2.3.0 and 2.26,
see :ref:`2.23 documentation <mirrors-anaconda-repository-2.23>`.
For documentation of older versions, please see :ref:`2.2 documentation <mirrors-sync-configuration-2.2>`.

Before you begin
================

You need to have already completed `installing and configuring your Anaconda Repository instance <install.html>`_.
Due to the size of the Anaconda Repository, it is important that you have configured a file storage location with
sufficient disk space.  If necessary please see the `instructions for setting the file storage location <install.html#configure-the-server>`_.

The full Anaconda mirror requires approximately 90GB.

Transition from anaconda-server-sync-conda to anaconda-mirror
=============================================================

Please :ref:`read our guide <mirrors-transition>` to transition from the previous to the new tool.


The mirror command
==================

You can mirror some or all of the contents of the `Anaconda repository <http://docs.continuum.io/anaconda/pkg-docs.html>`_ using the ``anaconda-mirror`` command::

    anaconda-mirror sync

This will mirror all of the packages from the Anaconda repository into the `anaconda` user account.

Verify by opening your browser to ``http://<your.anaconda.repo>/anaconda/``

NOTE: Replace ``<your.anaconda.repo>`` with the actual URL to your installation of Anaconda Repository.

Alternately, you may not wish to mirror all packages. To mirror a subset of the total repository,
specify which platforms you want to include, or use the whitelist, blacklist or license_blacklist
functionality to control which packages are mirrored by copying the default configuration file
``$PREFIX/etc/anaconda-server/mirror/anaconda.yaml`` to ``$PREFIX/etc/anaconda-server/mirror/anaconda-custom.yaml``::

    anaconda-mirror --config-file anaconda-custom sync

If necessary, refer to more information on :doc:`whitelist, blacklist and license_blacklist functionality <mirrors-sync-configuration>`.

Exporting a mirror
-------------------

Generate a mirror archive with this command::

    anaconda-mirror export mirror.tar

This will dump the packages, according to the :doc:`configured settings <mirrors-sync-configuration>`, into the file ``mirror.tar``.

This mirror can be used in an air-gapped environment.

Importing a mirror
------------------

To mirror the Anaconda repository in an air-gapped environment, using a system with no internet access,
point ``anaconda-mirror`` to the exported mirror archive.

Mount the USB drive and then run the following command::

    anaconda-mirror import $USB/mirror.tar

This will mirror the contents of the local Anaconda repository to your Anaconda Repository installation under the username ``anaconda``.

Filtering
---------

If you wish to update the filters on your mirror (for example, to exclude additional licenses), running ``anaconda-mirror sync`` again
will retrieve new packages that match this filter, but it will not remove existing packages that no longer match the filter.

To see which packages no longer match your filter, run the command::

    anaconda-mirror clean --dry-run

To remove these packages from your mirror, run the command::

    anaconda-mirror clean

Configure conda
===============

Having created the mirror, you will still need to configure conda to search for packages here rather than on the default Anaconda repository.  You can do that by editing your `~/.condarc` file to add the appropriate channel::

    channels:
        - http://<anaconda.repo.ipaddress>:<port>/conda/anaconda/

NOTE: Replace <anaconda.repo.ipaddress> with the actual URL to your installation of Anaconda Repository.

NOTE: This configuration change can be made at the user level or via an `administrative <http://conda.pydata.org/docs/admin.html>`_ conda file, to force all internal users to use your local Anaconda mirror rather than querying the Anaconda repository.

NOTE: Users can download Anaconda installers that are pre-configured to search your Repository from ``http://<anaconda.repository.addr>/downloads``. To
learn how to generate these installers, see the :ref:`bundled installers <bundled-installers>` documentation.
