# Backup / restore (testdb snapshot)

`veloce backup` writes the **testdb** snapshot: `testdb.bin` + `testdb.idx` + `testdb.recno` + `testdb.meta.json` + `pgw-pk/`. Same layout as workgroup `BACKUP TESTDB` (jsonl pointer + sibling `.disk/`).

This is **not** a Postgres dump, PG datadir, Redis RDB/AOF, SQL Server BAK, or Oracle backup. **pgwire is not a backup target.** `native=testdb`.

## CLI

```text
veloce help
veloce backup --dir ./data
veloce backup --dir ./data --dest s3://bucket/backups
veloce backups --dir ./data
veloce restore ./data/backups/testdb.latest.jsonl --dir ./restore
veloce restore s3://bucket/backups/testdb.latest.jsonl --dir ./restore
```

Reply line:

```text
OK native=testdb ts=2026-10-20T01:49:00.000Z dest=s3://bucket/backups/testdb.3.1729.jsonl rows=3 lsn=3 testdb snapshot …
```

Default dest is `{DATA_DIR}/backups`. `--dest` may be a local directory, `file://`, or cloud (`s3://` `gs://` `azure://`). Cloud dest still writes that local snapshot, then puts the pointer + `.disk/` files.

Workgroup HTTP: `GET /api/v1/backup` lists snapshots. `POST /api/v1/backup` with `{ "dest": "/mnt/offsite" }` or `{ "dest": "s3://bucket/backups" }` writes local + that dest.

`--dest` URIs: `file://`, path, `s3://`, `r2://`, `gs://`, `azure://`.

## Replicate (local + cloud destinations)

`veloce replicate run` takes **one** local snapshot, then **pushes** the same files to each configured destination. This is **not** streaming replication, not CDC, and not a substitute for cluster ship on 1584.

```text
veloce replicate catalog
veloce replicate add-dest s3://bucket/veloce-backups --dir ./data
veloce replicate run --dir ./data
veloce replicate status --dir ./data
```

Policy file: `{DATA_DIR}/testdb.replicate.json`. Workgroup: `SHOW REPLICATE`, `GET /api/v1/replicate`, `POST /api/v1/replicate/run`, `POST /api/v1/replicate/policy`.

Optional timer on the workgroup service: `VELOCE_REPLICATE_INTERVAL_MS` (minimum 60000). Extra URIs without editing policy: `VELOCE_REPLICATE_DEST` (comma-separated).

On the workgroup port (enterprise / trial): `BACKUP TESTDB` and `RESTORE TESTDB` stay the in-process snapshot. Optional URI: `BACKUP TESTDB s3://bucket/backups`. `SHOW BACKUP` lists `{DATA}/backups`.

## Cloud URIs

No secrets in the repo. Live put/get uses env creds / IAM-style keys.

| Scheme | Test double | Live env |
| --- | --- | --- |
| `file://` or a path | local file | local file |
| `s3://bucket/key` (S3-compatible / R2 via `AWS_ENDPOINT_URL`) | `VELOCE_S3_LOCAL_ROOT` maps to `{root}/{bucket}/{key}` | `AWS_ACCESS_KEY_ID` + `AWS_SECRET_ACCESS_KEY` (+ `AWS_REGION`) |
| `gs://bucket/key` | `VELOCE_GCS_LOCAL_ROOT` | `GOOGLE_ACCESS_TOKEN` |
| `azure://account/container/blob` | `VELOCE_AZURE_LOCAL_ROOT` | `AZURE_STORAGE_ACCOUNT` + `AZURE_STORAGE_KEY` or SAS |

`VELOCE_CLOUD_LOCAL_ROOT` is a shared fallback for those doubles.

## Refuse (not backup targets)

- Postgres data directory and `pg_dump`
- pgwire 15432 (wire sidecar on testdb)
- Redis RDB/AOF, SQL Server BAK/MDF, Oracle dump
- WAL-style incremental (leftover this cut)

## Leftover

Live S3/GCS/Azure without credentials leftover EXTERNAL. AWS SDK leftover EXTERNAL (this cut signs REST with Node `crypto`). Host kernel recut leftover EXTERNAL. Incremental / PITR leftover EXTERNAL.
