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
readandwritescopes, 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.
Find the staging environment
List the site's environments and note the
idof the one to copy onto.curl https://manage.corefinity.com/api/corestack/sites/1042/environments \ -H "Authorization: Bearer $COREFINITY_TOKEN" -H "Accept: application/json"Preview the copy
Ask from the environment you copy from, naming the target and what to copy:
files_db,dborfiles. Nothing changes.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_proceedtruewhen a copy sent now would be takenblockersWhat refuses the copy now, each with its reasonandmessagewaitsWhat 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 Start the copy
Send the same target and scope with the
preview_token, and the target environment's name, typed exactly, asconfirm_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.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 201The copy has started. Note operation.idand follow it in step 4202The copy waits its turn and starts by itself. Note queued.idand follow it in step 5Follow the operation
Read the operation every few seconds until its
statusiscompletedorfailed; see Long-running work.curl https://manage.corefinity.com/api/corestack/operations/5120 \ -H "Authorization: Bearer $COREFINITY_TOKEN" -H "Accept: application/json"Follow a copy that waits
Only for a copy that waits its turn. Read the queued copy until
queued.stateisstarted, then do step 4 with itsqueued.operation_id.The states
refused,expiredandcancelledmean the copy ended without starting, and nothing was copied.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 /. Once a copy has started it runs to its end.corestack/ copy-queue/ {queued}
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.