> ## Documentation Index
> Fetch the complete documentation index at: https://anaconda.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Managing mirrors with the CLI

Mirroring via the CLI can accomplish things that would be cumbersome via the GUI. For general information about mirrors, see [Mirrors](https://anaconda.com/docs/psm-on-prem/6.8.0/admin/mirrors.md).

Mirrors exist within channels in Package Security Manager. When working in the CLI, you need to create a channel to populate with a mirror or know which channels are already available. Anaconda recommends that channels contain only one mirror each to prevent conflicts between package sources and mirror filters. A channel can contain multiple mirrors, but you need to ensure your mirror filters do not overlap in a conflicting manner.

## Creating a mirror

The basic command for creating a mirror is:

```sh theme={null}
conda repo mirror --create <MIRROR_NAME> --channel <CHANNEL_NAME> --source <SOURCE> --type <TYPE> --mode <MODE> --run_now
```

Comments

Replace \<MIRROR\_NAME> with a name for your mirror.\\

Replace \<CHANNEL\_NAME> with the channel you want to contain your mirror.\\

Replace \<SOURCE> with the URL of the external repository to mirror.\\

Replace \<TYPE> with a valid mirror type (`conda`, `python_simple`, or `CRAN`).\\

Replace \<MODE> with either `active` or `passive`.

This creates an exact copy of the mirrored repository with no restrictions on what gets copied.

> [!TIP]
>
> To reduce CPU usage while a large mirror runs, you can freeze the channel first with `conda repo channel --freeze <CHANNEL_NAME>`. Packages don't appear in a frozen channel, so unfreeze it with `conda repo channel --unfreeze <CHANNEL_NAME>` when the mirror completes. For more information, see [Freezing and unfreezing channels](https://anaconda.com/docs/psm-on-prem/6.8.0/user/channel.md#freezing-and-unfreezing-channels).

> [!NOTE]
>
> Your mirror type *must* match the source repository. For example, if your source mirror contains conda packages, you must use `conda` as your mirror type.

You can add arguments to the basic mirror command to further specify configurations, such as restricting available packages or downloading only specific versions.

To create a mirror and populate it with a specific set of packages:

```sh theme={null}
conda repo mirror --create <MIRROR_NAME> --channel <CHANNEL_NAME> --source <SOURCE> --mode <MODE> --run_now --subdirs "<PLATFORMS>" --only_spec <PKG_NAME> --only_spec <PKG_NAME>
```

Comments

Replace \<MIRROR\_NAME> with a name for your mirror.\\

Replace \<CHANNEL\_NAME> with the channel you want to contain your mirror.\\

Replace \<SOURCE> with the URL of the external repository to mirror.\\

Replace \<MODE> with either `active` or `passive`.\\

Replace \<PLATFORMS> with a comma-separated list of platforms.\\

Replace \<PKG\_NAME> with the name of each package you want mirrored (repeat `--only_spec` for each).

For example, to create a mirror called "snakes" in a channel named "lua" and populate it with packages for Mac users only:

```sh theme={null}
conda repo mirror --create snakes --channel lua --source https://repo.anaconda.com/pkgs/main/ --run_now --mode passive --subdirs "noarch, osx-64, osx-arm64" --only_spec lua --only_spec ncurses --only_spec readline
```

> [!WARNING]
>
> Populating your channel with specific packages does not automatically include their dependencies. If you do not have all necessary packages, conda cannot create an environment from the channel.

## Creating a mirror with a policy

When you create or edit a mirror on a channel that has a policy, the channel's policy is automatically applied. To assign a specific policy to the mirror instead, include `--use-channel-policy False` and `--policy-id <POLICY_ID>`:

```sh theme={null}
conda repo mirror --create <MIRROR_NAME> --channel <CHANNEL_NAME> --source <SOURCE> --type <TYPE> --mode <MODE> --use-channel-policy False --policy-id <POLICY_ID> --run_now
```

Comments

Replace \<MIRROR\_NAME> with a name for your mirror.\\

Replace \<CHANNEL\_NAME> with the channel you want to contain your mirror.\\

Replace \<SOURCE> with the URL of the external repository to mirror.\\

Replace \<TYPE> with a valid mirror type (`conda`, `python_simple`, or `CRAN`).\\

Replace \<MODE> with either `active` or `passive`.\\

Replace \<POLICY\_ID> with your policy ID.

> [!WARNING]
>
> Don't combine `--policy-id` with mirror filter arguments such as `--only_spec` or `--subdirs`. The command fails with an error. Define those filters in the policy instead.

For more information, see [Policies](https://anaconda.com/docs/psm-on-prem/6.8.0/cli/policies.md).

## Filtering mirrored packages

> [!WARNING]
>
> Policies were introduced in Package Security Manager version 6.7.0. If your version supports policies, use [policy filtering](https://anaconda.com/docs/psm-on-prem/6.8.0/cli/policies.md) for channels that contain conda packages. For all other mirror types (Std Python, R), use the mirror filters described below.

Adding filters to your mirrors ensures you only mirror the packages you need. You can filter by platform, license, specific packages, CVE score, and date range. For more information about CVEs, see [Common Vulnerabilities and Exposures (CVEs)](https://anaconda.com/docs/psm-on-prem/6.8.0/admin/cve.md).

> [!NOTE]
>
> Filters can also be applied at the channel level. Both the channel filter and the mirror filter are applied. The mirror filter restricts packages pulled from the source mirror, and the channel filter restricts which packages are allowed into the channel. Filters should not contain configurations that conflict with one another.

### Platform filtering

`--subdirs`: Instruct Package Security Manager to only mirror packages for the provided subdirectories. Anaconda recommends you always include the noarch platform as well as the specific platform architectures necessary for your organization. Use a comma-separated string in double quotes:

```sh theme={null}
--subdirs "noarch,osx-64,osx-arm64"
```

Available platforms: `noarch`, `linux-32`, `linux-64`, `linux-aarch64`, `linux-armv6l`, `linux-armv7l`, `linux-ppc64`, `linux-ppc64le`, `osx-64`, `osx-arm64`, `win-32`, `win-64`, `zos-z`

> [!NOTE]
>
> If your source mirror does not contain conda packages, this argument is not necessary.

### Mirror type

`--type`: Denotes the mirror type. Possible types are `conda`, `python_simple`, and `CRAN`:

```sh theme={null}
--type "conda"
```

### PyPI project filtering

`--projects`: List of PyPI projects to mirror. Use a comma-separated string in double quotes:

```sh theme={null}
--projects "rxnpy,sympad,permutation"
```

### License filtering

`--licenses`: Include or exclude licenses. To exclude a license, prepend the entry with a hyphen (`-`). Use a comma-separated string in double quotes:

```sh theme={null}
--licenses "-public_domain,-none,mit,apache,agpl"
```

Available licenses: `agpl`, `gpl2`, `gpl3`, `lgpl`, `bsd`, `mit`, `apache`, `psf`, `public_domain`, `proprietary`, `other`, `none`

### Package filtering

`--only_spec`: Include a specific package from the source mirror. Uses MatchSpec to specify the package. Supply this argument multiple times for multiple entries.

> [!NOTE]
>
> For more information about MatchSpec queries, see [Package match specifications](https://docs.conda.io/projects/conda/en/latest/user-guide/concepts/pkg-specs.html#package-match-specifications).

`--exclude_spec`: Exclude a package from the source mirror. Supply this argument multiple times for multiple entries:

```sh theme={null}
--exclude_spec pytorch
```

`--include_spec`: Include a package (or a specific version) that would otherwise be excluded by `--exclude_spec`. Supply this argument multiple times for multiple entries:

```sh theme={null}
--include_spec pytorch==1.21.1
```

### CVE filtering

`--cve_score`: Remove all files associated with a CVE that has a score equal to or higher than the threshold value. CVE scores range from 0–10 and can contain up to one decimal point:

```sh theme={null}
--cve_score 7.1
```

`--exclude_uncurated_cve_packages`: Remove all files associated with uncurated CVEs. This argument takes no value:

```sh theme={null}
--exclude_uncurated_cve_packages
```

> [!NOTE]
>
> Package Security Manager 6.8.0 doesn't support `--exclude_uncurated_cve_packages` for conda mirrors. The mirror is created, but the filter is ignored. To exclude uncurated CVE packages, use the `--exclude-uncurated-cve-packages` option in a [policy](https://anaconda.com/docs/psm-on-prem/6.8.0/cli/policies.md#cve-filtering-options).

### Date filtering

`--date_from`: Start of a date range for when a conda package was published. Format: `YYYY-MM-DD`.

`--date_to`: End of a date range for when a conda package was published. Format: `YYYY-MM-DD`.

```sh theme={null}
--date_from 2022-03-01 --date_to 2022-05-15
```

> [!NOTE]
>
> A maximum span of one year is allowed between the start and end of the date range.

## Viewing mirror status

To view the status of a mirror:

```sh theme={null}
conda repo mirror --show <MIRROR_NAME> --channel <CHANNEL_NAME>
```

Comments

Replace \<MIRROR\_NAME> with the name of the mirror.\\

Replace \<CHANNEL\_NAME> with the name of the channel that contains the mirror.

Example output:

```text theme={null}
(base) ➜  ~ conda repo mirror --show boa --channel snakes
    Mirror Details:
    ---------------
    id: 29a15c15-49fc-4275-91c3-633129c6233c
    name: boa
    type: conda
    mode: active
    state: completed
    source root: http://repo.anaconda.com/pkgs/main
    Last run at: 2023-05-30T00:01:00.033756+00:00
    Updated at: 2023-05-30T00:06:11.705000+00:00
    created:
    cron: 0 0 * * *
    proxy:
    filters:
        only_specs               | ['numba', 'pytorch', 'pandas', 'panels', 'python==3.10']
```

## Stopping and restarting a mirror

To stop an in-progress mirror:

```sh theme={null}
conda repo mirror --stop <MIRROR_NAME>
```

Comments

Replace \<MIRROR\_NAME> with the name of the mirror.

To restart a stopped mirror:

```sh theme={null}
conda repo mirror --restart <MIRROR_NAME>
```

Comments

Replace \<MIRROR\_NAME> with the name of the mirror.

## Updating a mirror

To update an existing mirror, use the `--update` argument with the same [mirror arguments](#creating-a-mirror) used during creation:

```sh theme={null}
conda repo mirror --update <MIRROR_NAME> --channel <CHANNEL_NAME> --<ARG> --<ARG>
```

Comments

Replace \<MIRROR\_NAME> with the name of the mirror.\\

Replace \<CHANNEL\_NAME> with the channel that contains the mirror.

For example:

```sh theme={null}
conda repo mirror --update boa --channel snakes --only_spec jupyterhub --only_spec airflow --only_spec django --type conda --mode active --run_now
```

> [!NOTE]
>
> If you do not include the `--run_now` argument, your mirror updates on its next scheduled run. Run `conda repo mirror --update <MIRROR_NAME> --channel <CHANNEL_NAME> --run_now` to trigger an immediate update without changing any parameters.

> [!WARNING]
>
> Updating a mirror replaces its current contents with what you specify in the update command.

## Deleting a mirror

To delete a mirror:

```sh theme={null}
conda repo mirror --delete <MIRROR_NAME> --channel <CHANNEL_NAME>
```

Comments

Replace \<MIRROR\_NAME> with the name of the mirror.\\

Replace \<CHANNEL\_NAME> with the channel that contains the mirror.

> [!NOTE]
>
> When you create a conda mirror with filter arguments, Package Security Manager also creates a policy named `<MIRROR_NAME>_<ID>`. Deleting the mirror doesn't delete this policy. To remove it, find its ID with `conda repo policy --list-all`, and then run `conda repo policy --delete <POLICY_ID>`.

## Related

* [Mirrors](https://anaconda.com/docs/psm-on-prem/6.8.0/admin/mirrors.md): Managing mirrors through the GUI
* [Policies](https://anaconda.com/docs/psm-on-prem/6.8.0/cli/policies.md): Creating and managing security policies
* [`mirror` command reference](https://anaconda.com/docs/psm-on-prem/6.8.0/cli/commands/mirror): Full options and flags
