|
| 1 | +--- |
| 2 | +title: Export and restore a portable archive |
| 3 | +description: Create, validate, and restore a verified PowerContext logical bundle. |
| 4 | +--- |
| 5 | + |
| 6 | +# Export and restore a portable archive |
| 7 | + |
| 8 | +A portable archive is a `.pcb` file for moving or recovering complete PowerContext scopes. It is a logical archive: |
| 9 | +it preserves domain identities and immutable history rather than copying a SQLite file. Use it for a controlled local |
| 10 | +backup, an offline transfer, or a future backend migration. |
| 11 | + |
| 12 | +This command is a local operator command. It opens the default SQLite database in the PowerContext user-data directory; |
| 13 | +it does not call a remote Server API. Run it only on a machine whose local PowerContext data you control. |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | + |
| 17 | +Install the CLI from the same PowerContext revision that created the local data. The archive command uses the persistent |
| 18 | +SQLite database at `POWERCONTEXT_HOME/powercontext.db`; without `POWERCONTEXT_HOME`, PowerContext uses its operating |
| 19 | +system user-data directory. |
| 20 | + |
| 21 | +```bash |
| 22 | +uv tool install "powercontext[cli] @ git+https://github.com/oceanbase/powercontext.git@master" |
| 23 | +export POWERCONTEXT_HOME="$HOME/.local/share/powercontext" |
| 24 | +``` |
| 25 | + |
| 26 | +The archive contains content and metadata needed for recovery. Store it in a protected location with access controls |
| 27 | +and retention appropriate for the underlying project data. The format deliberately omits credentials and configured |
| 28 | +provider secrets, but it does not encrypt the project content. |
| 29 | + |
| 30 | +## Create and inspect an archive |
| 31 | + |
| 32 | +Pass every complete scope to include. A scope cannot be selected by prefix or partially by record type. |
| 33 | + |
| 34 | +```bash |
| 35 | +powercontext archive export \ |
| 36 | + --scope-id project:payments \ |
| 37 | + --output ./backups/payments.pcb |
| 38 | + |
| 39 | +powercontext archive inspect ./backups/payments.pcb |
| 40 | +``` |
| 41 | + |
| 42 | +`export` writes JSON containing the bundle ID, record count, and checksum. `inspect` verifies the ZIP structure, |
| 43 | +per-record digests, total digest, record counts, and selected scopes without opening the target database. Keep the |
| 44 | +reported checksum with the backup inventory if an external backup system needs an independent verification record. |
| 45 | + |
| 46 | +## Validate before a restore |
| 47 | + |
| 48 | +Always validate the archive against the destination first: |
| 49 | + |
| 50 | +```bash |
| 51 | +powercontext archive restore ./backups/payments.pcb --dry-run |
| 52 | +``` |
| 53 | + |
| 54 | +Dry-run performs no domain writes. It verifies checksums, required source and Artifact dependencies, and whether the |
| 55 | +configured Runtime can restore the archive's source types and Artifact families. A validation failure exits with code |
| 56 | +`2` and reports only a content-free reason; record bodies are not printed. |
| 57 | + |
| 58 | +To perform the write, repeat the command with explicit confirmation: |
| 59 | + |
| 60 | +```bash |
| 61 | +powercontext archive restore ./backups/payments.pcb --yes |
| 62 | +``` |
| 63 | + |
| 64 | +The result is JSON with `inserted`, `already_present`, and `projections_ready`. Treat the restore as ready for search |
| 65 | +only when `projections_ready` is `true`. The Runtime rebuilds portable Memory and Experience search projections after |
| 66 | +the authoritative rows have been restored. |
| 67 | + |
| 68 | +## What the bundle preserves |
| 69 | + |
| 70 | +Format version 1 carries the portable relational representation of these supported records: |
| 71 | + |
| 72 | +| Preserved | Not portable | |
| 73 | +| --- | --- | |
| 74 | +| Source journal heads and Source records | Search projections and indexes | |
| 75 | +| Artifact Revisions, lineage, and heads | Source cursors and scheduler state | |
| 76 | +| Memory entry versions and heads | External Skill registrations and host-local installation state | |
| 77 | +| Candidate versions, decision heads, and their evidence references | Usage statistics, credentials, bearer tokens, and provider secrets | |
| 78 | + |
| 79 | +The archive has a versioned manifest (`format_version`, producer version, scopes, counts, exclusions, and total |
| 80 | +checksum) plus NDJSON records. It is the authoritative round-trip format. CSV may be produced separately for bounded |
| 81 | +analysis, but it cannot preserve immutable revisions, lineage, or evidence references and must not be used for restore. |
| 82 | + |
| 83 | +## Recovery and conflicts |
| 84 | + |
| 85 | +Restore is idempotent. Replaying the same archive recognizes identical records as `already_present`. A different |
| 86 | +payload for an existing immutable identity never overwrites it: restore exits with code `3` and leaves the write |
| 87 | +transaction rolled back. Resolve the conflicting target data or choose a clean destination, then run the same restore |
| 88 | +command again. |
| 89 | + |
| 90 | +If the command is interrupted before completion, do not claim recovery succeeded. Authoritative records are |
| 91 | +transactionally applied, so a failed write does not leave a successful-looking partial restore. Re-run the same archive |
| 92 | +against the same destination after the previous command has stopped. |
| 93 | + |
| 94 | +## Current boundaries |
| 95 | + |
| 96 | +Export streams database rows to a temporary NDJSON file. Validation stores only record identities in a temporary |
| 97 | +on-disk index, and restore replays dependency levels as streams, so aggregate archive payloads are not retained in |
| 98 | +process memory. The local CLI always opens the default SQLite database under `POWERCONTEXT_HOME` (or the operating |
| 99 | +system user-data directory); it is not a remote Server API and does not use Server authentication or non-SQLite |
| 100 | +database settings. For a live production database, use the database provider's coordinated backup procedures. |
0 commit comments