# Migrate from Artifactory to CloudRepo

> One command moves Artifactory's local Maven repositories to CloudRepo, with every file checked.

`cloudrepo-migrate artifactory` copies the local Maven repositories of a JFrog Artifactory server into CloudRepo, then reads every file back from CloudRepo and checks it against the original. It moves every file of a Maven repository but a root `archetype-catalog.xml`, which the report names. From version 0.8.0 it also moves a local Generic repository you name with `--repo SOURCE=TARGET` into `TARGET`, a CloudRepo Maven repository, every file at the same path and served as it is, tested against a real Artifactory OSS 7.146.39. See [Generic repositories](#generic-repositories).

One command moves your Artifactory Maven repositories into CloudRepo, every file checksum-verified.

A dry run lists what would move and uploads nothing.

**Terminal**

```bash
cloudrepo-migrate artifactory \
  --artifactory-url https://artifactory.example.com/artifactory \
  --org your-org \
  --dry-run
```

When the list looks right, run it for real:

**Terminal**

```bash
cloudrepo-migrate artifactory \
  --artifactory-url https://artifactory.example.com/artifactory \
  --org your-org \
  --report-json report.json
```

Artifactory is only read. It keeps running, unchanged, until you repoint your builds. Using an agent? Go to [For agents](#for-agents). On Nexus? Use [`cloudrepo-migrate nexus3`](/docs/migrate/from-nexus-3.html) or [`nexus2`](/docs/migrate/from-nexus-2.html), the same tool with the same options.

## What you need

- A CloudRepo organization. No account yet? [Start free trial](https://www.cloudrepo.io/signup). 14 days free. No credit card required.
- A [repository](/docs/manage/repositories.html#creating-a-repository) in CloudRepo for each Artifactory repository you move, of the same format. Give it the Artifactory repository’s key, or map the names with `--repo`. A CloudRepo repository name has lowercase letters, digits, `_` and `-`, and at most 32 characters, so a key such as `libs-release-local` fits and a longer one needs `--repo`. Use a new, empty repository where you can: the tool puts each file at the path Artifactory has it, and a repository that allows overwrites replaces a file already there.
- A [repository token](/docs/authenticate/repository-tokens.html) with **Download and publish packages** on those repositories.
- Python 3.8 or later with pipx (or pip), on a machine that can reach your Artifactory server and your CloudRepo organization over the network.
- An Artifactory access token that can read the repositories. A legacy API key works too.

## 1. Install the tool

`cloudrepo-migrate` is one command for Python 3.8 or later, with no dependencies. Install it from PyPI:

**Terminal**

```bash
pipx install cloudrepo-migrate
```

No pipx? `pip install cloudrepo-migrate` in a virtual environment works too. Then check that it runs:

**Terminal**

```bash
cloudrepo-migrate --version
```

`artifactory` needs version 0.5.0 or later. If you installed the tool earlier for Nexus, run `pipx upgrade cloudrepo-migrate`. An older version answers `invalid choice: 'artifactory'`. Generic repositories move from version 0.8.0, when `--repo` names them. Earlier versions list them as skipped.

## 2. Run it

Put the credentials in the environment of the shell that runs the tool: `ARTIFACTORY_ACCESS_TOKEN` for Artifactory, and `CLOUDREPO_TOKEN` for CloudRepo. Without an access token, the tool sends `ARTIFACTORY_API_KEY` instead (JFrog has deprecated API keys, so prefer a token). The tool reads them only from the environment. No option takes a credential, the tool never prints one or writes one to the report, and it sends the Artifactory credential only to the address you give it. It never follows a redirect, so the credential cannot be sent on to another host.

The first command at the top of this page is the dry run. With `CLOUDREPO_TOKEN` set, it also checks the token and that each target repository exists. The second command is the real run.

| Option                               | Meaning                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--artifactory-url URL`              | The base address of your Artifactory, ending in `/artifactory`, such as `https://artifactory.example.com/artifactory`. On JFrog Cloud, it is your server’s address followed by `/artifactory`.                                                                                                                                                                                                                                                                 |
| `--org ORG` or `--cloudrepo-url URL` | Your CloudRepo organization, or its full `https` address.                                                                                                                                                                                                                                                                                                                                                                                                      |
| `--repo SOURCE` or `SOURCE=TARGET`   | Move only this Artifactory repository, to the CloudRepo repository `TARGET` (default: the same name). Repeat it for more. Default without it: every local Maven repository. A local Generic repository moves only when named here, from version 0.8.0, into a CloudRepo Maven repository `TARGET`.                                                                                                                                                             |
| `--dry-run`                          | List what would move. Upload nothing.                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `--quote`                            | From version 0.10.0. Count what you have, to ask us for a quote. It prints only totals: the repositories, the files and the bytes, and how many repositories could not be listed. It counts the files Artifactory stores, not the `.sha1` and `.md5` it serves beside them. It names nothing about your server, so you can send it to us as it is. It only reads Artifactory: it implies `--dry-run`, needs no `--org`, and stops if `CLOUDREPO_TOKEN` is set. |
| `--report-json PATH`                 | Also write the report to `PATH` as JSON.                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `--json`                             | Print the report as one JSON document on standard output, and the text on standard error.                                                                                                                                                                                                                                                                                                                                                                      |
| `--jobs N`                           | Upload `N` Maven files at a time (default 4).                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `--work-dir DIR`                     | Where a Maven file is held while it moves (default: the system temporary directory).                                                                                                                                                                                                                                                                                                                                                                           |
| `--artifactory-ca-file PEM`          | A CA bundle, for an Artifactory with a private certificate.                                                                                                                                                                                                                                                                                                                                                                                                    |

## What moves, and what does not

| In Artifactory                         | What happens                                                                                                                                                                                                                                                                                                                                                                                                  |
| -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Local repository, package type Maven   | Every file moves, POMs and `maven-metadata.xml` included, except a root `archetype-catalog.xml` (below). Artifactory serves each file’s `.sha1` and `.md5` without storing them, so the tool writes both into CloudRepo from the file’s checked bytes, and Maven finds them as it did in Artifactory. The `maven-metadata.xml` files move last, so a build never reads a version whose files have not landed. |
| Local repository, package type Generic | From version 0.8.0, moves only when `--repo` names it: every file it stores moves into `TARGET`, a CloudRepo Maven repository, at the same path and served as it is, a dot file and a root `archetype-catalog.xml` included, with no `.sha1` or `.md5` written beside it. Without `--repo` naming it, it is skipped with a reason that names the flag. See [Generic repositories](#generic-repositories).     |
| Remote repository                      | Skipped. Create a [proxy repository](/docs/consume/proxy-repositories.html) in CloudRepo if its upstream is one CloudRepo offers.                                                                                                                                                                                                                                                                             |
| Virtual repository                     | Skipped: it stores nothing of its own. Move the local repositories it includes. For Maven, Docker, PyPI and npm (PyPI and npm in early access), you can then create a [group repository](/docs/manage/repositories.html#creating-a-repository) in CloudRepo to serve them under one address.                                                                                                                  |
| Federated repository                   | Skipped. This version moves local repositories.                                                                                                                                                                                                                                                                                                                                                               |
| Any other package type                 | Not covered by this guide. This version of the guide covers Maven. A Generic repository moves from version 0.8.0 when `--repo` names it. For the other formats CloudRepo hosts, export and import the files as [Migrate from Sonatype Nexus Repository](/docs/migrate/from-nexus.html#3-export-the-files) shows for any server.                                                                               |
| Files Artifactory generates itself     | Skipped: any file or folder whose name starts with a dot, such as the Maven index under `.index`. In a Generic repository a dot file moves, as a file someone stored.                                                                                                                                                                                                                                         |
| A root `archetype-catalog.xml`         | Not moved from a Maven repository: this version moves no archetype catalog. The report says so on that repository’s line. Deploy the catalog to CloudRepo yourself. From a Generic repository it moves, as any other file.                                                                                                                                                                                    |

Every skipped repository is in the report with its reason. The tool deletes nothing.

## Generic repositories

From version 0.8.0, a local Generic repository moves when you name it with `--repo`, into a CloudRepo Maven repository. CloudRepo has no Generic repository type: [a Maven repository serves any file at any path](/docs/formats/raw.html), so installers, archives and other binaries keep the paths your scripts already fetch. Tested against a real Artifactory OSS 7.146.39.

- **Every file, at the same path.** Every file the Generic repository stores moves into the CloudRepo Maven repository at the path Artifactory has it, and CloudRepo serves it as it is, so only the address before the path changes. A file or folder whose name starts with a dot, and a root `archetype-catalog.xml`, move too: in a Generic repository each is a file someone stored.
- **Every file is checked against the checksum Artifactory recorded.** Before the upload, the bytes must match the SHA-256 and SHA-1 Artifactory lists for the file, and Artifactory must have listed one of them: a file with neither is not uploaded. After the upload, the tool reads the file back from CloudRepo and compares its SHA-1 and SHA-256.
- **No checksum file is added.** Unlike for a Maven file, the tool writes no `.sha1` or `.md5` beside a Generic file: those are a Maven client’s, and only what Artifactory stores moves. A checksum file Artifactory stores moves as a file, and must name the digest of the file beside it.
- **A file CloudRepo cannot store fails, in a dry run too.** A path with a character outside `A-Z a-z 0-9 + _ - . ! * ' ( ) / @ ~`, longer than 1024 characters, or with an empty, `.` or `..` segment, and a file over 50,000,000,000 bytes, the most CloudRepo stores in one file, are each listed as a failure with the path, so the exit code is `1`. A `--dry-run` lists the same failures, before anything moves.
- **Unnamed, it is skipped, with the flag to use.** Without `--repo` naming it, a Generic repository is skipped as `generic format is not supported by default: name it with --repo KEY=TARGET to move its files into a CloudRepo Maven repository TARGET, each at the same path`.
- **`--repo` moves only what it names.** Name your other repositories beside the Generic one, or move the Generic one in a run of its own.

Create a Maven repository in CloudRepo for each Artifactory Generic repository you move. In the commands below, replace `generic-local` with the key of your Artifactory Generic repository, and `installers` with the CloudRepo Maven repository it moves into. A dry run counts the files and bytes, lists each file CloudRepo cannot store, and uploads nothing:

**Terminal**

```bash
cloudrepo-migrate artifactory \
  --artifactory-url https://artifactory.example.com/artifactory \
  --org your-org \
  --repo generic-local=installers \
  --dry-run
```

When the list looks right, run it for real:

**Terminal**

```bash
cloudrepo-migrate artifactory \
  --artifactory-url https://artifactory.example.com/artifactory \
  --org your-org \
  --repo generic-local=installers \
  --report-json report.json
```

Run the second command again to resume: a file CloudRepo already holds with the same bytes is counted as already present. After the move, fetch each file from CloudRepo at its same path, as [Raw files over HTTP](/docs/formats/raw.html) shows.

## How every file is checked

1. **Before the upload.** A file’s bytes must match the SHA-256 and SHA-1 Artifactory lists for it. A file that does not match is not uploaded.
2. **After the upload.** The tool reads the file back from CloudRepo and compares its SHA-1 and SHA-256 with the bytes it took from Artifactory.
3. **Checksum files.** The `.sha1` and `.md5` the tool writes for a Maven repository come from the bytes it downloaded and checked, never from Artifactory’s numbers alone, and are read back the same way. For a Generic repository it writes none.
4. **Generic.** A Generic file is checked as a Maven file is, and Artifactory must have listed its SHA-256 or SHA-1, or it is not uploaded, as [Generic repositories](#generic-repositories) says.

Any mismatch fails the run and names the file. The run then exits with `1`, so a script or an agent cannot read a failed check as success.

## Resume after a failure

Run the same command again. A file CloudRepo already holds is counted as already present, and not uploaded again, only after the tool has read it back and found the same bytes. A repository that refuses to overwrite a release answers `409` for a file it holds. The tool counts that file as moved only when the bytes CloudRepo holds match the source.

## The end report

The last line of the output is the result:

```text
Moved N repositories, F files, B bytes in M minutes; V of F verified, K failed.
```

`N`, `F` and `B` are the repositories, files and bytes that moved, `M` is the elapsed time, `V` is the number of Maven files read back and matching, and `K` is the number that failed. Above it is one line for each repository: its Artifactory key, its CloudRepo name, its format, its counts and, for a skipped repository, why.

`--report-json` writes the same report as JSON, and `--json` prints it as one JSON document on standard output (the text then goes to standard error). A script reads these keys:

| Key                                    | Holds                                                                                                                             |
| -------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| `exit_code`                            | The exit code of the run, as in [If something fails](#if-something-fails).                                                        |
| `error`                                | The message of a run that stopped before its report, such as a refused token. Such a document holds only `exit_code` and `error`. |
| `totals.files`, `.verified`, `.failed` | The counts in the last line.                                                                                                      |
| `failures`                             | One entry for each failed file, with its `repository`, `path` and `reason`. Empty when nothing failed.                            |
| `repositories[].action`                | `moved`, `would move` (a dry run), `skipped`, `ready` or `blocked`.                                                               |
| `repositories[].reason`                | Why a repository was skipped or blocked, or a root `archetype-catalog.xml` that did not move.                                     |

## If something fails

The exit code says which kind of failure it was:

| Exit code | Meaning                                                                                                          |
| --------- | ---------------------------------------------------------------------------------------------------------------- |
| `0`       | Everything moved, and every Maven file was read back and matched.                                                |
| `1`       | At least one file failed. The output lists each one with its path. Fix the cause and run the same command again. |
| `2`       | A problem before anything moved, such as a missing target repository or a refused token. Nothing was uploaded.   |
| `130`     | Stopped with Ctrl-C. Run the same command again to resume.                                                       |

The messages you are most likely to see:

| The output says                                                                                  | What to do                                                                                                                                                                                                                                                 |
| ------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `CloudRepo has no repository NAME: create it as ...`                                             | Create the repository in CloudRepo, in the format named, then run again. Or map the Artifactory repository to another with `--repo`.                                                                                                                       |
| `... is not a valid CloudRepo repository name`                                                   | The Artifactory key is not a valid CloudRepo name. Choose a name with `--repo SOURCE=TARGET`.                                                                                                                                                              |
| `CloudRepo refused the token`                                                                    | Check `CLOUDREPO_TOKEN`, and that the token belongs to this organization.                                                                                                                                                                                  |
| `the token cannot reach CloudRepo repository NAME`, or `cannot publish`                          | Give the token **Download and publish packages** on that repository.                                                                                                                                                                                       |
| `Artifactory refused the login`                                                                  | Set `ARTIFACTORY_ACCESS_TOKEN` to a token that can read the repository.                                                                                                                                                                                    |
| `the bytes Artifactory served ... do not match the ... Artifactory recorded`                     | The copy in Artifactory does not match its own record, so the tool did not upload it. Check that file in Artifactory.                                                                                                                                      |
| `Artifactory recorded no sha1 or sha256 for the file, so it cannot be checked before the upload` | A Generic file Artifactory lists no SHA-256 or SHA-1 for, so the tool did not upload it. Check that file in Artifactory.                                                                                                                                   |
| `CloudRepo cannot store this path (...)`                                                         | The path has a character outside the ones the message lists, is longer than 1024 characters, or has an empty, `.` or `..` segment, so the file does not move. The other files do. Rename it in Artifactory to move it; until then the run keeps exiting 1. |
| `the file is SIZE bytes, over the 50000000000 bytes CloudRepo stores in one file`                | The file is larger than CloudRepo stores in one file, so it does not move. The other files do, and the run keeps exiting 1 while the file is in the repository you move.                                                                                   |
| `answered 302, a redirect to ...`                                                                | Artifactory sent the download to another address, as some storage setups do. The tool never follows a redirect, so your credential stays with Artifactory. Email <support@cloudrepo.io> with the message.                                                  |
| `CloudRepo already holds different bytes for this path and refuses overwrites`                   | The file in CloudRepo is not the one in Artifactory, and the repository will not replace it. Decide which copy is right, then email <support@cloudrepo.io> with the path.                                                                                  |
| `the bytes CloudRepo serves back differ from the source`                                         | Run the same command again. If the same file fails twice, email <support@cloudrepo.io> with its path.                                                                                                                                                      |

## After the move

The files are in CloudRepo, and your builds still point at Artifactory. Repoint them one project at a time, as step 5 of [Migrate from Sonatype Nexus Repository](/docs/migrate/from-nexus.html#5-repoint-your-builds) shows for each build tool, with your Artifactory address where that page has the Nexus one, and leave Artifactory running until your builds pass against CloudRepo.

## For agents

Give your agent this instruction. It carries the address of this page as plain text, so the agent reads this page and nothing else:

```text
Migrate my Artifactory to CloudRepo. Follow https://www.cloudrepo.io/docs/migrate/from-artifactory.md. Read my credentials from the environment variables ARTIFACTORY_ACCESS_TOKEN and CLOUDREPO_TOKEN, and ask me for the Artifactory URL and the CloudRepo organization if you do not have them.
```

The invocation, in two runs. Replace the address and the organization with the owner’s:

**Terminal**

```bash
cloudrepo-migrate artifactory --artifactory-url https://artifactory.example.com/artifactory --org your-org --dry-run --json
cloudrepo-migrate artifactory --artifactory-url https://artifactory.example.com/artifactory --org your-org --json
```

Each run prints one JSON document on standard output, its result, and the text report on standard error. [The end report](#the-end-report) names the keys.

Steps:

1. Check that `python3 --version` is 3.8 or later. If `cloudrepo-migrate --version` does not answer, install the tool with the command in [Install the tool](#1-install-the-tool), and check again. If it answers a version older than 0.5.0, run `pipx upgrade cloudrepo-migrate`, and check again. If `cloudrepo-migrate artifactory --help` does not list `--json`, run `pipx upgrade cloudrepo-migrate`. If it still does not, run each command with `--report-json report.json` in place of `--json`, and read `report.json`: the same document, without `exit_code`.

2. Check that `CLOUDREPO_TOKEN` is set without printing it, for example with `test -n "$CLOUDREPO_TOKEN"`. Do the same for `ARTIFACTORY_ACCESS_TOKEN`, or for `ARTIFACTORY_API_KEY` if the owner uses an API key.

3. Run the first command, the dry run. It reads Artifactory and writes nothing to CloudRepo. Expect exit code `0`, and in the document `exit_code` `0` and `dry_run` `true`. Each entry in `repositories` with the action `would move` is a repository that will move, with its `format` and `files`; each with the action `skipped` says why in its `reason`. On exit code `2`, read `error`, or the `reason` of each repository with the action `blocked`, in [If something fails](#if-something-fails). If a target repository is missing, ask the owner to create it in the portal, then repeat the dry run.

4. Run the second command.

5. Verify, all of these, in the document it printed:

   - `exit_code` is `0`, and so is the exit code of the command.
   - `failures` is empty, `totals.failed` is `0` and `totals.verified` equals `totals.files`.
   - No entry in `repositories` has the action `blocked`.

6. Tell the owner `totals.repositories`, `totals.files` and `totals.verified`, and every repository with the action `skipped` and its reason.

If the exit code is `1`, read each entry in `failures`, with its `path` and `reason`, remove its cause, and run the second command again, which resumes. If the same file fails twice, stop and report its path and reason to the owner.

Do not put a credential on a command line, in a file or in your answer. Do not change anything in Artifactory. Do not repoint builds or switch CI to CloudRepo until the owner tells you to.

---

The page: https://www.cloudrepo.io/docs/migrate/from-artifactory.html
