---
title: "Clone production to staging"
url: https://docs.corefinity.com/api/recipes/clone-production-to-staging
type: page
last_updated: 2026-11-13
feature: recipe-clone-production-to-staging
---
# Clone production to staging

Preview a copy of production onto a staging environment, start it and follow it until it finishes.

A copy brings one environment's files and database onto another environment of the same site. This recipe copies the production site `harbourandfinch.example.com` onto its staging environment.

## Before you start

- A token with the `read` and `write` [scopes](/api/scopes), and a person who can change both environments.
- Every step needs [two-factor enrolment](/api/two-factor) when your company requires it.
- No step waits for a maintenance window. A copy can wait its turn behind another change; step 5 follows that.

1. **Find the staging environment**

   List the site's environments and note the `id` of the one to copy onto.

   ```bash
   curl https://manage.corefinity.com/api/corestack/sites/1042/environments \
     -H "Authorization: Bearer $COREFINITY_TOKEN" -H "Accept: application/json"
   ```

2. **Preview the copy**

   Ask from the environment you copy from, naming the target and what to copy: `files_db`, `db` or `files`. Nothing changes.

   ```bash
   curl "https://manage.corefinity.com/api/corestack/sites/1042/clone/preview?target_type=environment&target_id=1043&scope=files_db" \
     -H "Authorization: Bearer $COREFINITY_TOKEN" -H "Accept: application/json"
   ```

   | Field           | Meaning                                                         |
   | --------------- | --------------------------------------------------------------- |
   | `can_proceed`   | `true` when a copy sent now would be taken                      |
   | `blockers`      | What refuses the copy now, each with its `reason` and `message` |
   | `waits`         | What a copy sent now would wait for before it starts by itself  |
   | `fixups`        | What is adjusted on the target after the copy, in plain words   |
   | `preview_token` | The token the copy must quote. It lasts 15 minutes              |

3. **Start the copy**

   Send the same target and scope with the `preview_token`, and the target environment's name, typed exactly, as `confirm_name`.

   > **Warning:** The copy replaces the staging environment's files and database with production's. With `safety_first: true`, the default, a safety copy of the staging environment is kept first.

   ```bash
   curl -X POST https://manage.corefinity.com/api/corestack/sites/1042/clone \
     -H "Authorization: Bearer $COREFINITY_TOKEN" -H "Accept: application/json" \
     -H "Content-Type: application/json" \
     -d '{"target": {"type": "environment", "environment_id": 1043}, "scope": "files_db", "safety_first": true, "preview_token": "cp_Xq7mR2vK9sLp4TzW8nBd", "confirm_name": "Staging"}'
   ```

   | Status | Meaning                                                                                |
   | ------ | -------------------------------------------------------------------------------------- |
   | `201`  | The copy has started. Note `operation.id` and follow it in step 4                      |
   | `202`  | The copy waits its turn and starts by itself. Note `queued.id` and follow it in step 5 |

4. **Follow the operation**

   Read the operation every few seconds until its `status` is `completed` or `failed`; see [Long-running work](/api/long-running-work).

   ```bash
   curl https://manage.corefinity.com/api/corestack/operations/5120 \
     -H "Authorization: Bearer $COREFINITY_TOKEN" -H "Accept: application/json"
   ```

5. **Follow a copy that waits**

   Only for a copy that waits its turn. Read the queued copy until `queued.state` is `started`, then do step 4 with its `queued.operation_id`.

   The states `refused`, `expired` and `cancelled` mean the copy ended without starting, and nothing was copied.

   ```bash
   curl https://manage.corefinity.com/api/corestack/copy-queue/6120 \
     -H "Authorization: Bearer $COREFINITY_TOKEN" -H "Accept: application/json"
   ```

   To withdraw a copy while it waits, send `DELETE /corestack/copy-queue/{queued}`. Once a copy has started it runs to its end.

## Copy onto production

The same two requests push staging to live: ask from the staging environment with `target_type=production`, and send `target.type` `production` with the site's domain as `confirm_name`. That copy replaces production, always keeps a safety copy first, and needs the `destructive` scope as well.

## If it is refused

| Status | `reason`            | What to do                                                                                                                                                           |
| ------ | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `404`  | `feature_off`       | Copying between environments is not on for your company                                                                                                              |
| `422`  | `invalid`           | Correct the field named in `field` and `errors`. On `preview_token`: the preview is older than 15 minutes or was asked with another target or scope; do step 2 again |
| `422`  | `confirm_mismatch`  | Send the target environment's name exactly as `confirm_name`                                                                                                         |
| `409`  | `copy_queued`       | A copy onto this environment already waits its turn. Follow it, or withdraw it first                                                                                 |
| `409`  | `target_busy`       | A change is running on the target and copies do not wait for it. Try again when it has finished                                                                      |
| `409`  | `clone_in_progress` | Another copy is running on the site. Wait for it to finish                                                                                                           |
| `409`  | `maintenance`       | Production is in maintenance mode, which refuses a copy onto production. Switch it off first                                                                         |

Starting a copy allows 5 requests a minute; see [Rate limits](/api/rate-limits).
