Files
tessera/README.md
Adnan Zahir 6320b6f244 feat: add managed database capture and operator restore
PostgreSQL and MySQL backups run through paired outposts, with operator sign-in, off-site copies, and legacy import. Retention stays on each orbit, so the unused retention console is removed.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-10 23:26:49 +07:00

98 lines
8.5 KiB
Markdown

# Tessera
Self-hosted backup vault with a space-themed canvas: **orbits**, **snapshots**, **decay**, and **wormhole** outposts.
## Quick start
For a native install, put [Restic 0.19.1 or newer](https://restic.readthedocs.io/en/stable/020_installation.html) on the hub and CLI's `PATH`. The Docker image includes Restic.
```bash
# Build UI then hub
cd web && npm ci && npm run build && cd ..
cargo build --release -p tessera-hub
export TESSERA_DATA_DIR=./data
export TESSERA_VAULT_PASSPHRASE='choose a long private passphrase'
./target/release/tessera-hub
```
The hub listens on **127.0.0.1:8787** unless `TESSERA_LISTEN` is set. Open [http://127.0.0.1:8787](http://127.0.0.1:8787). The OpenAPI document is at `/api-doc/openapi.json`. There is no default passphrase, and new vaults refuse the old published value `dev-vault-key`. Leave `TESSERA_SEED_DEMO` unset; `TESSERA_SEED_DEMO=1` writes demo backup history into the data directory.
With neither operator sessions nor an admin token configured, the admin API is available on loopback only. Set `TESSERA_ADMIN_TOKEN` for API/CLI access and pass it as `Authorization: Bearer <token>` or `X-Tessera-Admin-Token`. To sign in from the dashboard, configure the separate [operator password hash](docs/DATABASE-CAPTURE.md#operator-sign-in).
### Docker Compose
```bash
export TESSERA_VAULT_PASSPHRASE='choose a long private passphrase'
docker compose up --build
```
Compose publishes **127.0.0.1:8787** only. The process inside the container listens on `0.0.0.0:8787` so that published port can reach it. The image includes `pg_dump` via `postgresql-client`.
### CLI
```bash
cargo build --release -p tessera-cli
export TESSERA_VAULT_PASSPHRASE='choose a long private passphrase'
./target/release/tessera init
./target/release/tessera orbit nightly --path ./docs
./target/release/tessera snap
./target/release/tessera list
```
## Deduplicated backups
New captures use Restic. Orbits select **Filesystem / Folder** or **Database**, then **Via Hub** or **Via Outpost**. Filesystem orbits executed by the hub back up files directly and share encrypted chunks in `vault/restic`. Each successful run creates a complete restore point. The API reports `size_bytes` for the logical backup, `stored_bytes` for new packed data and metadata, and `new_data_chunks` for newly stored payload chunks. An identical backup can add metadata while reporting zero new data chunks.
Restore a new filesystem or Restic outpost snapshot to a file such as `restore.tar`. PostgreSQL and legacy upload restores still produce the original payload bytes. Existing snapshots use their original storage and restore format. Keep the entire `vault` directory and its passphrase together when moving a Tessera installation.
Decay removes expired snapshots from Tessera's list. Run `tessera gc` periodically from the host or container with the same data directory and vault passphrase to let Restic reclaim their unreferenced chunks. Run it during a quiet period so Restic can acquire its repository locks. Legacy packs and Restic snapshots created outside Tessera's catalog require separate maintenance.
### Custom retention
Choose **Custom (GFS)** in an orbit's retention settings. Each count selects the newest snapshot in each of the most recent occupied UTC days, ISO weeks (Monday to Sunday), months, or years. Empty periods do not use up a count. A snapshot can satisfy more than one tier. Set a tier to zero to skip it and keep at least one tier above zero. Existing presets keep their original behavior.
To set 7 daily, 2 weekly, 6 monthly, and 3 yearly snapshots from the CLI:
```bash
tessera orbit archive --path /srv/archive --keep-daily 7 --keep-weekly 2 --keep-monthly 6 --keep-yearly 3
tessera retention <orbit-id> --keep-daily 7 --keep-weekly 2 --keep-monthly 6 --keep-yearly 3
```
The API accepts `{"retention":{"keep_daily":7,"keep_weekly":2,"keep_monthly":6,"keep_yearly":3}}` as part of `POST /api/v1/orbits` or as the body of `PUT /api/v1/orbits/{id}/retention`. Omitted tiers default to zero. To switch back to a preset, send `{"decay_preset":"week-of-dailies"}` to the same `PUT` endpoint or use `tessera retention <orbit-id> --preset week-of-dailies`. Saving applies the policy after the next successful capture. The separate `tessera decay --preset` command applies its selected preset to legacy snapshots. Managed captures use their profile policy.
### Managed database backups
[Pair an agent and register a capture profile](docs/DATABASE-CAPTURE.md) for PostgreSQL or MySQL. Profiles support direct connections and pinned SSH, scheduled capture, job history, downloads, and optional S3 copies. The managed path stores dumps in the hub's existing Restic repository.
### Incremental Wormhole transfers for filesystem archives
The same repository setup is used by new [Outpost backup profiles](docs/DATABASE-CAPTURE.md).
Run [Rest Server](https://github.com/restic/rest-server#usage) with TLS, authentication, `--append-only`, and `--private-repos`. Point its storage at the hub's `vault/outposts` directory. Both processes need filesystem access to that directory. Give Rest Server access only to `outposts`, with a separate location for its TLS and authentication files.
1. Pair the agent as usual. Save the outpost UUID and upload token from the pairing response. Create an orbit with `tessera orbit <name> --provider wormhole`. The agent's `run` command handles scheduling.
2. Initialize a Restic repository at `vault/outposts/<orbit-id>` with a unique repository password. Create a Rest Server login named `<orbit-id>` with a separate HTTP password. Put a mode `0600` file named `vault/keys/outpost-<orbit-id>.json` on the hub with the fields `outpost_id` (the paired UUID) and `password` (that repository's password). Back up this configuration with the vault.
3. On the agent, set `TESSERA_HUB_URL`, `TESSERA_UPLOAD_TOKEN`, `TESSERA_ORBIT_ID`, and `TESSERA_RESTIC_REPOSITORY` (for example, `rest:https://backup.example.org/<orbit-id>/`). Supply the repository password via `RESTIC_PASSWORD_FILE` or `RESTIC_PASSWORD`, and Rest Server credentials via `RESTIC_REST_USERNAME` and `RESTIC_REST_PASSWORD`. Run `tessera-agent beam` from the directory to back up. For a private Rest Server CA, set `RESTIC_CACERT` on the agent.
The agent reads files to detect changes, sends missing chunks and metadata through Restic, and then registers the successful snapshot with Tessera. Agents using the original Wormhole upload mode still send their full archive. The hub deduplicates that archive on disk.
If the Restic backup succeeds and registration fails, retry `POST /api/v1/wormhole/restic/commit` with the paired `X-Tessera-Upload-Token` and a JSON body containing `orbit_id` and the Restic `snapshot_id` from the error. Repeating registration for the same snapshot returns the same Tessera snapshot ID.
## Architecture
See [docs/SPEC.md](docs/SPEC.md). Rust workspace crates: `tessera-core`, `tessera-store`, `tessera-providers`, `tessera-hub`, `tessera-agent`, `tessera-cli`.
## Limitations (v1)
- New vaults derive the key with Argon2id (19 MiB, 2 iterations, parallelism 1) and record `keys/kdf.json`. A vault that already has a salt and no `kdf.json` still opens with PBKDF2-HMAC-SHA256, 100,000 iterations. New snapshot metadata is written as `{id}.json.enc`. Existing `{id}.json` files still list and restore.
- Wormhole pairing codes and upload tokens are stored in SQLite and survive a hub restart. Chunks are written at the given offset. When the bytes cover `total_bytes`, the hub seals them into the vault and deletes the `.part` file. `total_bytes` is required.
- Set `TESSERA_WORMHOLE_MTLS` to `1` or `true` to open a client-certificate listener. It also needs `TESSERA_WORMHOLE_CERT`, `TESSERA_WORMHOLE_KEY`, and `TESSERA_WORMHOLE_CLIENT_CA`. `TESSERA_WORMHOLE_LISTEN` defaults to `127.0.0.1:8788`. While that listener is up, plain HTTP upload routes answer 403. An agent needs `TESSERA_WORMHOLE_CLIENT_CERT` and `TESSERA_WORMHOLE_CLIENT_KEY` for that listener. Configure `TESSERA_WORMHOLE_CA` when the hub certificate uses a private CA.
- PostgreSQL captures still run a full `pg_dump` into a private temporary file. Restic can deduplicate matching bytes in the resulting dump. Allow temporary disk space for one full dump per concurrent capture. The release image includes `pg_dump`; a native hub needs it on `PATH`.
- The command provider is outside this release. Creating a command orbit and running it returns `command provider is outside this release; use filesystem or postgres`.
- OIDC is not implemented. The canvas does not attach `TESSERA_ADMIN_TOKEN`.
## License
AGPL-3.0-or-later — see [LICENSE](LICENSE).