Skip to main content
You can import a Perforce depot into a new Diversion repository, history included. The import runs on a machine you provide, called the import host, which needs network access to your Perforce server. Your Perforce password stays on the import host; Diversion never receives it. The Diversion app creates the repository and an API token and generates the configuration file the import host needs. A script on the import host then runs the import in Docker, checking in with Diversion every 5 minutes.
If you can’t run the import yourself (for example, your machines run only Windows), request a managed import instead.

Requirements for the import host

  • A Unix machine with bash and cron
  • Docker Engine 20.10 or newer, with the Docker Compose plugin 2.17 or newer
  • Network access to your Perforce server and to Diversion over HTTPS
  • Optional: curl and the AWS CLI. Without them, the script runs them from a container image instead.

Set up the import in the Diversion app

1

Open the Perforce import page

In the Diversion app, click New repository and choose Import from P4. You can also choose Import from Perforce at the bottom of the repository menu in the breadcrumbs.New repository menu with Import from P4
On self-hosted installs, Import from P4 opens a request form instead, and the Diversion team runs the import for you.
2

Download the import script

Click Download p4_import_bootstrap.sh. The script is the same for every import, and you can download it from this page at any time.
3

Name the new repository

The repository name is filled in from the depot name; change it if you like. The repository must belong to an organization. If you don’t have one yet, you can create it here.
4

Fill in the import settings

See Import settings below for what each field does.Import from Perforce page with the repository and import settings filled in
5

Click 'Create repository and import files'

Diversion creates the repository, an API token, and your import configuration.
6

Download local.env

Click Download local.env. The file contains the API token, your repository ID and the setup steps.API token, Download local.env button and import host setup steps
The API token is shown only once. Download local.env before you leave the page — if you leave without it, see Recover a lost local.env.

Import settings

Protect local.env

local.env holds an API token with admin access to your Diversion account. Treat it like a password:
  • Keep it only on the import host, readable only by the user that runs the import (chmod 600 local.env, as in the steps below).
  • Don’t commit it to version control, share it in chat or email, or copy it to other machines.

Run the import on the import host

Run these steps as the user that will run the import — a user with access to Docker. Don’t use sudo: it would install the schedule in root’s crontab.
1

Put both files in one directory

Copy p4_import_bootstrap.sh and local.env into the same directory on the import host, for example /opt/dv-p4-import, and cd into it.
2

Make the script executable

3

Fill in your Perforce settings

Open local.env and fill in the Perforce connection at the bottom of the file:
Leave API_DOMAIN, API_TOKEN and REPO_ID as generated.
4

Protect local.env

5

Run the script once to check the setup

A successful first run downloads your import configuration, pulls the Diversion import image and starts it. The output includes a line like Remote env changed -- recreating: ..., and docker ps shows the import container running. The first run can take a few minutes while images download.
6

Schedule the import

This adds a crontab entry that runs the script every 5 minutes from this directory and appends its output to bootstrap.log. Each run restarts the import if it stopped and applies any change to its configuration.

Follow the import’s progress

Open the new repository in Diversion. Until the import finishes, the repository page shows its progress through three stages: Reading history, Preparing history and Uploading files. Commits, branches and files appear once history is ready. Files open as soon as their contents are uploaded. Large depots take a long time to import. The import host must stay on and connected until it finishes.

Stop or remove the import

The crontab entry keeps the import running until you remove it.
Keep the crontab entry if you need continuous import from Perforce, or export back to it, after the initial import. Contact support to enable continuous import or export.
When the import is done and you don’t need it to continue:
  1. Run crontab -e and delete the line containing p4_import_bootstrap.sh.
  2. Delete local.env from the import host.

Troubleshooting

The script writes errors to its output and, once scheduled, to bootstrap.log in the import directory.

Recover a lost local.env

If you left the Import from Perforce page before downloading local.env, don’t start a new import: the repository and its import settings already exist. Recreate the file instead.
1

Create local.env

On the import host, create local.env next to p4_import_bootstrap.sh with this content:
local.env
2

Fill in REPO_ID

In the Diversion app, click the repository name in the breadcrumbs to open the list of your organization’s repositories. Hover over the row of the new repository and click the Copy repo ID button that appears. Paste the ID as REPO_ID.Repository menu in the breadcrumbs with the Copy repo ID button
3

Fill in API_TOKEN

If you copied the token from the import page, paste it as API_TOKEN.If you didn’t, generate a new one:
  1. Click your avatar (top-right) and choose Integrations from the menu.
  2. Click Generate a new API token, give it a name, and click Generate token. Generate it while signed in as the user who created the repository, so the token has admin access to it.
  3. Copy the token and paste it as API_TOKEN. It’s shown only once.
Integrations page with the Generate a new API token button
4

Continue the setup

Follow Run the import on the import host from the start.

Request a managed import

If you can’t meet the requirements above, we can run the import for you. Use Request a managed import at the bottom of the Import from Perforce page, or contact us at support@diversion.dev.