CorefinityCorefinityDocs
Open the Control PanelControl Panel
Recipes · 3 of 8

Clone production to staging

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

On this page

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, and a person who can change both environments.
  • Every step needs two-factor enrolment 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.

    Terminal
    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.

    Terminal
    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"
    FieldMeaning
    can_proceedtrue when a copy sent now would be taken
    blockersWhat refuses the copy now, each with its reason and message
    waitsWhat a copy sent now would wait for before it starts by itself
    fixupsWhat is adjusted on the target after the copy, in plain words
    preview_tokenThe 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.

    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.

    Terminal
    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"}'
    StatusMeaning
    201The copy has started. Note operation.id and follow it in step 4
    202The 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.

    Terminal
    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.

    Terminal
    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

StatusreasonWhat to do
404feature_offCopying between environments is not on for your company
422invalidCorrect 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
422confirm_mismatchSend the target environment's name exactly as confirm_name
409copy_queuedA copy onto this environment already waits its turn. Follow it, or withdraw it first
409target_busyA change is running on the target and copies do not wait for it. Try again when it has finished
409clone_in_progressAnother copy is running on the site. Wait for it to finish
409maintenanceProduction 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.

Was this helpful?
Open in ClaudeOpen in ChatGPT