=======
Mirrors
=======

Mirroring is the process of copying the contents of an external repository locally, ensuring users have fast and reliable access to its packages. When you run a mirror, it populates your channel with packages from the mirror's source. Anaconda recommends that channels contain *only one mirror each* to prevent conflicts between package sources. 

For more information on channels, see :doc:`Channels and subchannels <../user/channel>`.

.. note:: 
    
    Mirroring is restricted to users whose :ref:`role <per_lvls_and_cats>` provides ``write`` or ``manage`` permissions for **Channel Mirrors** and/or **Subchannel Mirrors** categories.

Allowlist the following URLs before attempting to mirror:
    * https://repo.anaconda.com/
    * https://repo.anaconda.cloud/
    * https://anaconda.org/
    * https://anaconda.com/
    * https://api.anaconda.cloud/
    * https://conda.anaconda.org/
    * https://pypi.org/
    * https://files.pythonhosted.org/
    * https://cran.r-project.org/ (optional - for CRAN R users)

Creating a mirror
=================

When creating a mirror, the recommended workflow is:

#. Select a channel you want to contain your mirror.
#. Open the |gear| **Manage** dropdown menu and select *Freeze*.
#. Click **Freeze**. 
#. Open the |gear| **Manage** dropdown menu again and select *Create Mirror*.
#. Complete the :ref:`Create mirror <create-mirror-form>` form.
#. Allow the mirror time to complete.

    .. dropdown:: How do I know when my mirror is complete? 
        :color: primary
        :animate: fade-in

        You can view the status of in progress mirrors from the **All repository mirrors** page, or from a channel's **Mirrors** tab. In-progress mirrors display which step is currently being performed with a brief description of the operation. 

            .. thumbnail:: ../img/as_mirror_status.png
                :align: center

#. Open the |gear| **Manage** dropdown and select *Unfreeze*.
#. Click **Unfreeze**. 

.. note:: 

    For more information on freezing and unfreezing a channel, see :ref:`Freezing/Unfreezing Channels <freeze_unfreeze>`.

.. _create-mirror-form:

Create mirror form
------------------

The **Create mirror** form allows you to set the configurations for your mirror. Let's take a look at the different sections of the **Create mirror** form and what configurations they control.

.. thumbnail:: ../img/as_create_mirror_ui_6.7.0.png
   :align: center

#. **Mirror Name** 
    Enter a name for your mirror. Anaconda recommends you name your mirror something descriptive for your end users.

#. **Mirroring mode**
    Choose whether you want your mirror to be active or passive. 

    **Active mirroring**

    Active mirroring will download all the packages not filtered out of your mirror immediately to your local server. These mirrors can be extremely large in size; the Anaconda's public repository is 700GB, the conda-forge repository is 3TB, and the PyPI repository is 10TB in their entirety! Due to this, active mirrors can take a long time to complete.

    **Passive mirroring**

    Passive mirroring creates a metadata file that is a complete list of packages on the mirrored server. When a user needs a package, they can run conda install ``<PKG_NAME>``  and the requested package will be downloaded from the source at that time.

    .. note:: 

        Regardless of which mirror you choose to create, the packages will be the same. Anaconda recommends establishing your mirrors as passive.

#. **External Source URL**
    This is the URL of the server/repository you want to mirror.

    Anaconda recommends creating mirrors for the following external source channels:
     * https://repo.anaconda.cloud/pkgs/main
     * https://repo.anaconda.cloud/pkgs/msys2
     * https://repo.anaconda.cloud/pkgs/r 

    .. note:: 
       
       If your external source channel is another channel within Package Security Manager, you must use the format ``https://<URL>/api/repo/<CHANNEL_NAME>``.

       If your external source channel is a channel from Anaconda Business, you must use the format ``https://repo.anaconda.cloud/repo/t/<TOKEN>/<ORG_ID>/<CHANNEL_NAME>``.

#. **Mirror Type** 
    Set the type of packages that will be mirrored from the external source channel. This should align with the selection on the **Create Channel** form. Packages in this mirror that do not match the channel package type will be filtered out.

    You can choose from conda, standard python, or standard R package types. *Make sure you have allowlisted the URLs listed at the top of this page before creating mirrors*. 

#. **Mirroring Frequency** 
    Set the frequency you want your mirror to run and update your packages. The default value instructs the mirror to update at midnight on the first day of every month.

    Custom frequencies use `cron expressions <https://crontab.cronhub.io/>`_ to determine when they run.  

    .. caution::
        
        Mirroring large channels can take several hours. Anaconda recommends against setting a frequency greater than *Daily* to avoid collisions between currently running and updating mirrors.

    .. warning:: 

        If you are mirroring the full PyPI repository, set your frequency to run once yearly. Once the PyPI mirror is complete, any attempts to re-run the mirror will cause issues. 

#. **Run Now** 
    Check this box to start your mirror when you click **Save & Run**. If the **Run Now** box was not checked, your changes are saved, and the mirror runs the next time its frequency configuration instructs it to do so.

#. **Assign Mirror Policy**
    Toggle between using the policy that is applied to the channel or selecting a policy to apply to the mirror. For more information about policies, see :doc:`Policies <policies>`.

    .. note:: 

        You cannot apply a policy to a mirror if it is already applied to the channel. 

#. **View Applied Policy**
    View the details of the applied policy.

#. **Cancel/Save & Run** 
    Select **Cancel** at any time to quit your mirror form completion and discard any set parameters. Select **Save & Run** to start your mirror. 

Managing mirrors
================

Select |all-mirrors| **All Mirrors** from the left-hand navigation to view mirrors globally for all users. 

.. note:: 
   
    * This view is only available to users whose role provides ``Manage`` permissions for the **mirror** attribute. This value must be assigned in Keycloak.

.. thumbnail:: ../img/as_all_repository_mirrors.png
    :align: center

.. tip:: 

    Use the search box to locate a mirror by name. Click a column header to sort mirrors by **Type**, **Mode**, **Mirroring Status**, or **Last Updated**.

Mirror actions
--------------

Use the icons in the **Actions** column to manage your mirrors:

.. thumbnail:: ../img/mirror_actions.png
    :align: center

.. tip::

    Mirror actions can also be performed from a channel's **Mirrors** tab.

|pencil| **Edit mirror** - Edit a mirror's configurations. 

    .. note:: 
        
        You cannot edit the mode of an established mirror.

|stop| **Stop running mirror** - Stop an in-progress mirror. 

    .. note:: 

        It can take up to 10 minutes for a mirror to fully stop. A mirror in the process of stopping will display **Stopping** as its mirroring status. Once it is complete, it will display **Stopped** as its status. Stopping a mirror does not discard the progress the mirror has made, and some packages may appear in your channel's **Packages** tab.

|restart| **Restart Mirror** - Restart a stopped mirror.

    .. note::

        Restarted mirrors run from the beginning of the mirroring process, not from where you stopped the run. 

|eye| **See details** - View information about how many packages were filtered from the source, reasons for their exclusion, and whether packages were mirrored passively or actively.

|trash| **Delete mirror** - Delete a mirror. 

.. _dependency_report:

|download| **Download Dependency Report** -  Download a dependency report (if available)

    * A dependency report is a detailed list of all the software packages required for your specified packages to function correctly. It includes both direct dependencies (packages your specified packages require to run) and indirect dependencies (packages the dependencies require to run). A package dependency report can help you identify exactly which packages are necessary for your channel to be able to create a working environment using conda.

    * Dependency reports are only available for mirrors that have policies with specific configurations applied:
        * You must set package rules to allow packages by their names using `MatchSpec protocol <https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/models/match_spec>`_—a syntax for specifying package names and versions in conda
        * You must select the **Include dependencies** checkbox.

.. |ellipsis-vertical| raw:: html

   <i class="fa-light fa-ellipsis-vertical"></i>

.. |circle-info| raw:: html
   
   <i class="fa-light fa-circle-info"></i>

.. |pencil| raw:: html

   <i class="fa-light fa-pencil"></i>

.. |mirror| raw:: html

   <svg class="inline" width="1.2em" height="1em" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path d="M384 352H224c-17.7 0-32-14.3-32-32V64c0-17.7 14.3-32 32-32H332.1c4.2 0 8.3 1.7 11.3 4.7l67.9 67.9c3 3 4.7 7.1 4.7 11.3V320c0 17.7-14.3 32-32 32zM433.9 81.9L366.1 14.1c-9-9-21.2-14.1-33.9-14.1H224c-35.3 0-64 28.7-64 64V320c0 35.3 28.7 64 64 64H384c35.3 0 64-28.7 64-64V115.9c0-12.7-5.1-24.9-14.1-33.9zM64 128c-35.3 0-64 28.7-64 64V448c0 35.3 28.7 64 64 64H224c35.3 0 64-28.7 64-64V416H256v32c0 17.7-14.3 32-32 32H64c-17.7 0-32-14.3-32-32V192c0-17.7 14.3-32 32-32h64V128H64z"/></svg>

.. |stop| raw:: html

    <svg class="inline" width="1.2em" height="1em" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path d="M320 80c26.5 0 48 21.5 48 48V384c0 26.5-21.5 48-48 48H64c-26.5 0-48-21.5-48-48V128c0-26.5 21.5-48 48-48H320zM64 64C28.7 64 0 92.7 0 128V384c0 35.3 28.7 64 64 64H320c35.3 0 64-28.7 64-64V128c0-35.3-28.7-64-64-64H64z"/></svg>

.. |trash| raw:: html

     <i class="fa-light fa-trash" style="color: #ff0000"></i>

.. |eye| raw:: html

    <svg class="inline" width="1.2em" height="1em" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path d="M106.3 124.3C151.4 82.4 212.4 48 288 48s136.6 34.4 181.7 76.3c44.9 41.7 75 91.7 89.1 125.6c1.6 3.9 1.6 8.4 0 12.3C544.7 296 514.6 346 469.7 387.7C424.6 429.6 363.6 464 288 464s-136.6-34.4-181.7-76.3C61.4 346 31.3 296 17.2 262.2c-1.6-3.9-1.6-8.4 0-12.3C31.3 216 61.4 166 106.3 124.3zM288 32c-80.8 0-145.5 36.8-192.6 80.6C48.6 156 17.3 208 2.5 243.7c-3.3 7.9-3.3 16.7 0 24.6C17.3 304 48.6 356 95.4 399.4C142.5 443.2 207.2 480 288 480s145.5-36.8 192.6-80.6c46.8-43.5 78.1-95.4 93-131.1c3.3-7.9 3.3-16.7 0-24.6c-14.9-35.7-46.2-87.7-93-131.1C433.5 68.8 368.8 32 288 32zM192 256a96 96 0 1 1 192 0 96 96 0 1 1 -192 0zm208 0a112 112 0 1 0 -224 0 112 112 0 1 0 224 0z"/></svg>

.. |download| raw:: html

    <svg class="inline" width="1.2em" height="1em" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M272 16c0-8.8-7.2-16-16-16s-16 7.2-16 16V329.4L139.3 228.7c-6.2-6.2-16.4-6.2-22.6 0s-6.2 16.4 0 22.6l128 128c6.2 6.2 16.4 6.2 22.6 0l128-128c6.2-6.2 6.2-16.4 0-22.6s-16.4-6.2-22.6 0L272 329.4V16zM140.1 320H64c-35.3 0-64 28.7-64 64v64c0 35.3 28.7 64 64 64H448c35.3 0 64-28.7 64-64V384c0-35.3-28.7-64-64-64H371.9l-32 32H448c17.7 0 32 14.3 32 32v64c0 17.7-14.3 32-32 32H64c-17.7 0-32-14.3-32-32V384c0-17.7 14.3-32 32-32H172.1l-32-32zM432 416a24 24 0 1 0 -48 0 24 24 0 1 0 48 0z"/></svg>

.. |gear| raw:: html

    <svg class="inline" xmlns="http://www.w3.org/2000/svg" height="20" width="20" viewBox="0 0 512 512"><path d="M211.6 28.5c1.6-7.3 8.1-12.5 15.6-12.5h57.6c7.5 0 14 5.2 15.6 12.5l12.9 57.1c.6 2.6 2.5 4.8 5 5.7c17.9 6.8 34.5 16.4 49.1 28.4c2.1 1.7 4.9 2.2 7.4 1.4l56-17.4c7.1-2.2 14.9 .8 18.6 7.3L478.3 161c3.7 6.5 2.5 14.7-3 19.8l-43.1 39.8c-2 1.8-2.9 4.5-2.5 7.2c1.5 9.2 2.3 18.7 2.3 28.4s-.8 19.1-2.3 28.4c-.4 2.6 .5 5.3 2.5 7.2l43.1 39.8c5.5 5.1 6.7 13.3 3 19.8L449.4 401c-3.7 6.5-11.5 9.5-18.6 7.3l-56-17.4c-2.6-.8-5.4-.3-7.4 1.4c-14.6 11.9-31.2 21.6-49.1 28.4c-2.5 1-4.4 3.1-5 5.7l-12.9 57.1c-1.6 7.3-8.1 12.5-15.6 12.5H227.2c-7.5 0-14-5.2-15.6-12.5l-12.9-57.1c-.6-2.6-2.5-4.8-5-5.7c-17.9-6.8-34.5-16.4-49.1-28.4c-2.1-1.7-4.9-2.2-7.4-1.4l-56 17.4c-7.1 2.2-14.9-.8-18.6-7.3L33.7 351c-3.7-6.5-2.5-14.7 3-19.8l43.1-39.8c2-1.8 2.9-4.5 2.5-7.2C80.8 275.1 80 265.7 80 256s.8-19.1 2.3-28.4c.4-2.6-.5-5.3-2.5-7.2L36.7 180.7c-5.5-5.1-6.7-13.3-3-19.8L62.6 111c3.7-6.5 11.5-9.5 18.6-7.3l2.4-7.6-2.4 7.6 56 17.4c2.6 .8 5.4 .3 7.4-1.4c14.6-12 31.2-21.6 49.1-28.4c2.5-1 4.4-3.1 5-5.7l12.9-57.1zM227.2 0c-15 0-27.9 10.4-31.2 25L184 78c-16.7 6.8-32.2 15.8-46.1 26.7L85.9 88.5C71.6 84 56.2 90.1 48.7 103L19.9 153c-7.5 13-5 29.4 6 39.5l39.9 36.9C64.6 238.1 64 247 64 256s.6 17.9 1.8 26.6L25.9 319.5l5.4 5.9-5.4-5.9c-11 10.1-13.5 26.6-6 39.5L48.7 409c7.5 13 22.9 19 37.2 14.6l51.9-16.2c14 10.9 29.5 19.9 46.1 26.7l12 53c3.3 14.6 16.3 25 31.2 25h57.6c15 0 27.9-10.4 31.2-25l12-53c16.7-6.7 32.2-15.8 46.1-26.7l51.9 16.2c14.3 4.4 29.7-1.6 37.2-14.6L492.1 359c7.5-13 5-29.4-6-39.5l-39.9-36.9c1.2-8.7 1.8-17.6 1.8-26.6s-.6-17.9-1.8-26.6l39.9-36.9c11-10.1 13.5-26.6 6-39.5L463.3 103c-7.5-13-22.9-19-37.2-14.6l-51.9 16.2C360.2 93.7 344.7 84.7 328 78L316 25c-3.3-14.6-16.3-25-31.2-25H227.2zM192 256a64 64 0 1 1 128 0 64 64 0 1 1 -128 0zm144 0a80 80 0 1 0 -160 0 80 80 0 1 0 160 0z"/></svg>

.. |all-mirrors| raw:: html

    <svg class="inline" width="1.2em" height="1em" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 589 512"><path d="M517 73.9H314L261.7 21.6A74.1 74.1 0 0 0 209.5 0H74A73.9 73.9 0 0 0 .1 73.9V443A73.9 73.9 0 0 0 74 516.9H517a73.9 73.9 0 0 0 73.9-73.9V147.7A73.9 73.9 0 0 0 517 73.9zM109.9 192a18.6 18.6 0 0 1 18.2-12.8h61.1l-18.7 74.5H76.9zM337.6 412.2a27.9 27.9 0 0 1 -28 27.9H104.8A27.9 27.9 0 0 1 76.9 412.2V272.5H170v46.6a9.3 9.3 0 0 0 9.3 9.3h55.8a9.3 9.3 0 0 0 9.3-9.3V272.5h93.2zM244.5 254 225.9 179.2h61.1a18.6 18.6 0 0 1 17.7 12.8l33 61.8z"/></svg>

.. |channels| raw:: html

    <svg class="inline" width="1.2em" height="1em" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M192 24c0 13.3 10.7 24 24 24c137 0 248 111 248 248c0 13.3 10.7 24 24 24s24-10.7 24-24C512 132.5 379.5 0 216 0c-13.3 0-24 10.7-24 24zm24 80c-13.3 0-24 10.7-24 24s10.7 24 24 24c79.5 0 144 64.5 144 144c0 13.3 10.7 24 24 24s24-10.7 24-24c0-106-86-192-192-192zm-7 233l40-40c9.4-9.4 9.4-24.6 0-33.9s-24.6-9.4-33.9 0l-40 40L71 199c-13.5-13.5-35.9-12.3-45.1 4.4C9.4 233.2 0 267.5 0 304C0 418.9 93.1 512 208 512c36.5 0 70.8-9.4 100.6-25.9c16.7-9.2 17.8-31.6 4.4-45.1L209 337zM48 304c0-18.1 3-35.5 8.5-51.6L259.6 455.5C243.5 461 226.1 464 208 464c-88.4 0-160-71.6-160-160z"/></svg>

.. |restart| raw:: html

    <svg xmlns="http://www.w3.org/2000/svg" width="1.2em" height="1em" viewBox="0 0 512 512"><path d="M384.1 419.9c-90.5 70.7-221.2 54.7-292-35.8s-54.7-221.2 35.8-292c90.5-70.7 221.2-54.7 291.9 35.8L456 176H328c-4.4 0-8 3.6-8 8s3.6 8 8 8H472c4.4 0 8-3.6 8-8V40c0-4.4-3.6-8-8-8s-8 3.6-8 8V160l-31.4-41.8 0 0-.1-.1C356.4 20.6 215.6 3.3 118.1 79.5S3.3 296.4 79.5 393.9s216.9 114.8 314.4 38.6c24.7-19.3 44.2-42.7 58.4-68.6c2.1-3.9 .7-8.7-3.2-10.9s-8.7-.7-10.9 3.2c-13.2 24-31.3 45.7-54.3 63.7z"/></svg>