What approaches can be used to validate that a CircleCI backup fully restores a project’s configuration and data integrity?
0 reputation · 14 Dec 2023, 04:40 UTC
0 reputation · 14 Dec 2023, 04:40 UTC
Validating a CircleCI backup requires confirming that the exported archive contains every element necessary to rebuild the project’s configuration, workflows, and associated artifacts, while also preserving any runtime‑generated values such as environment variables or dynamic parameters.
Because the restoration must be tested without impacting the primary pipeline, an isolated environment is needed, and the comparison must rely on static analysis of the configuration files and deterministic artifact checks rather than on executing the restored workflows in production.
What techniques exist to verify that all configuration keys, including those set via context or parameters, are present in the backup? How can one compare the workflow graph of the restored project to the original without triggering a build? Which artifact comparison methods provide sufficient assurance of data integrity while respecting the isolation constraint?
26525 reputation · 14 Dec 2023, 09:40 UTC
To prove that a CircleCI backup fully restores a project, you need a two‑phase audit:
curl -s -H "Circle-Token: $TOKEN" \
https://circleci.com/api/v2/project/github/$ORG/$REPO/config | jq .config | tee original-config.yaml
sha256sum original-config.yaml > original.sha
curl -s -H "Circle-Token: $TOKEN" \
https://circleci.com/api/v2/project/github/$ORG/$REPO/config | jq .config | tee restored-config.yaml
sha256sum restored-config.yaml > restored.sha
diff original.sha restored.sha
If the files differ, investigate added or missing keys. The jq .config step removes the metadata block that CircleCI injects on export, keeping the comparison deterministic.curl -X POST -H "Content-Type: application/json" \
-d @restored-config.yaml \
https://circleci.com/api/v2/project/github/$ORG/$REPO/config/validate
The response must be {"valid":true}.
circleci contexts list --org $ORG > contexts.txt
Run a small, idempotent job that generates a predictable artifact (e.g., a checksum of a static file). Use the same job in both environments.
.circleci/config.yml:
jobs:
validate:
docker:
- image: cimg/base:stable
steps:
- checkout
- run: echo "foo" > /tmp/foo.txt
- run: sha256sum /tmp/foo.txt > /tmp/foo.sha
- store_artifacts:
path: /tmp/foo.sha
circleci run --job validate
curl -s -H "Circle-Token: $TOKEN" \
https://circleci.com/api/v2/project/github/$ORG/$REPO/artifact/1 | sha256sum
Use the runs endpoint to verify that the restored project has the same number of completed runs and that no runs are missing.
curl -s -H "Circle-Token: $TOKEN" \
https://circleci.com/api/v2/project/github/$ORG/$REPO/runs | jq '.items | length'
Compare the counts from the original and restored projects.
If your backup includes external objects (S3, Docker images), download the same object from both environments and compare file sizes and checksums. For Docker images, use docker pull and docker inspect --format='{{.Id}}' to confirm identical layers.
To tailor the validation further, it would help to know whether your project uses dynamic contexts or runtime‑generated environment variables that are not captured in the static config export.
Use comments to ask for clarification. Post a solution as an answer.
26,525 reputation · 14 Dec 2023, 15:49 UTC
A useful boundary to set for this audit is that CircleCI does not provide a customer-operable full-org backup. Validation therefore focuses on configuration-as-code and API-accessible metadata, not a complete historical data dump.
Project settings, contexts, webhooks and environment variable values live outside the repository. Context variable values and personal API tokens cannot be exported for security reasons, so a restored target must be checked by name, scope and enabled features via an API inventory, with secrets recreated manually and verified by a test job that references the context.
Because of that, acceptance criteria are typically defined per project and verified in an isolated test org to avoid naming collisions and rate limits on production.