Skip to main content

Workspace backup automation

These workspace operations are separate from recipe transfer. Before automating them, check the backup and restore guide for what the file includes, what it omits, and what can change on import.

OperationMethod and pathWorkspace key scope
Export workspace backupGET /api/v1/workspaces/{workspaceId}/admin/backups/exportBACKUPS_EXPORT
Import workspace backupPOST /api/v1/workspaces/{workspaceId}/admin/backups/importBACKUPS_IMPORT

These are runtime routes with hand-written handlers. They aren't present in the current committed OpenAPI path set, so the generated API Reference may not list them; use the paths and scopes above.

An Admin or Owner session can also use these operations in the app. The instance master key is accepted but not necessary; for master-key imports with calculations, the destination must have a real workspace Owner or Admin to attribute them to. Keep a scheduled export on an export-only workspace key. Grant import separately and only for planned restores: BACKUPS_IMPORT can change many resources without their individual write scopes.

Save an export​

Use the cm_api helper in the quickstart, but load an export-only key into it. The quickstart's workspace_id expression assumes COCKTAILS_READ; for an export-only key, derive the ID from the BACKUPS_EXPORT permission instead:

identity=$(cm_api "$base_url/api/v1/me")
workspace_id=$(jq -er '
.data
| select(.isMaster == false and (.permissions | index("BACKUPS_EXPORT") != null))
| .workspaceId | select(type == "string" and length > 0) | @uri
' <<<"$identity")
workspace_api="$base_url/api/v1/workspaces/$workspace_id"

Confirm the returned workspace name and ID before using workspace_api for the backup.

umask 077
backup_dir=$(mktemp -d './workspace-backup.XXXXXXXX') &&
cm_api --output "$backup_dir/backup.partial" \
"$workspace_api/admin/backups/export" &&
jq -e 'type == "object" and (.cocktailRecipe | type == "array")' \
"$backup_dir/backup.partial" >/dev/null &&
mv "$backup_dir/backup.partial" "$backup_dir/backup.json"

The response is the raw backup JSON: save the whole object, not .data. This example checks for a backup-shaped response before naming the file backup.json. It is not a full validation or restore test. A failed request can leave backup.partial; don't treat it as a backup. Store successful exports securely and test a restore into an isolated workspace before relying on them.

Import a saved file​

Only run this against a verified destination after checking the restore guide. Load the destination's BACKUPS_IMPORT key into cm_api and set base_url and workspace_api to the destination origin and workspace ID. Post the raw file with Content-Type: application/json: no data or exportData wrapper, multipart form, or import phase.

cm_api --header 'Content-Type: application/json' \
--data-binary "@$backup_dir/backup.json" \
"$workspace_api/admin/backups/import"

HTTP 200 returns a raw object with msg: "Success" and report.skipped. Inspect the array even on success: items can be skipped by security checks and reported with their type, name and reason. A malformed archive or broken reference can produce a 400 with error.code, error.message and, when provided, error.issues.

The app validates the backup and uses one write transaction, with a 10-minute transaction timeout. The upload limit is 100 MB before any lower ingress limit. Have your operator check timeouts and request size limits on the whole path. The operation is not idempotent. If the connection closes without a result, inspect the destination or check with the operator before retrying. A browser console on a different origin isn't an appropriate backup client: these handlers don't use the cross-origin wrapper used by the core API.