feat: use Restic for encrypted incremental backups

Keep legacy restores readable while using Restic for new captures, scoped Wormhole repositories, and chunk garbage collection.
This commit is contained in:
2026-11-10 10:48:05 +07:00
parent 95778d54e4
commit 749c4cc828
15 changed files with 955 additions and 119 deletions

View File

@@ -4,6 +4,8 @@ Self-hosted backup vault with a space-themed canvas: **orbits**, **snapshots**,
## 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 ..
@@ -33,22 +35,41 @@ Compose publishes **127.0.0.1:8787** only. The process inside the container list
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 --dry-run
./target/release/tessera orbit nightly --path ./docs
./target/release/tessera snap
./target/release/tessera list
```
## Deduplicated backups
New captures use Restic. Filesystem orbits 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.
### Incremental Wormhole transfers
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)
- Vault engine uses a **restic-compatible directory layout** with Tessera’s own chunk encryption (Rust 1.83 cannot yet depend on `rustic_core` 0.13+). Emergency tooling may use external `rustic`/`restic` as formats converge.
- 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 that uses `https://` needs `TESSERA_WORMHOLE_CA`, `TESSERA_WORMHOLE_CLIENT_CERT`, and `TESSERA_WORMHOLE_CLIENT_KEY`.
- Postgres capture shells out to `pg_dump`. The connection URL is parsed and the password is written to a mode `0600` pgpass file (`PGPASSFILE`); it is not placed on the process argument list. The release image installs `pg_dump`; a hub built from source needs it on `PATH`.
- 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`.