# Managed database backups A capture profile maps one application and Wormhole orbit to a paired outpost. The hub stores the assignment, format, schedule, and retention policy. The agent reads connection settings and password references from its local profile file. Each application has one active capture lease. An agent can serve several applications in parallel. ## Pair an agent Build the hub, CLI and agent with `cargo build --workspace`. Put Restic on the hub and the database client for the source server version on the agent. SSH profiles also use OpenSSH on the agent. MySQL remote capture runs the server-compatible `mysqldump` on the SSH host. Generate a pairing code in **Outposts** or call `POST /api/v1/wormhole/pairing` with operator credentials. On the agent, create the credential file once. ```sh tessera-agent --hub-url https://backup.example.org --credentials /etc/tessera/wormhole.json pair CODE --name database-outpost tessera-agent --credentials /etc/tessera/wormhole.json --capture-profiles /etc/tessera/capture.json run ``` The credentials file is owner-only and contains the hub URL, outpost UUID and upload token. Keep it outside the repository. TLS uses the system trust store. Set `TESSERA_WORMHOLE_CA` for a private CA and configure both `TESSERA_WORMHOLE_CLIENT_CERT` and `TESSERA_WORMHOLE_CLIENT_KEY` for a hub that requires mTLS. Plain HTTP capture is available on loopback for local testing. ## Register an application In **Orbits**, choose **Database** or **Filesystem / Folder**, then **Via Outpost**. Save the orbit and register its Outpost backup profile. Pick the paired Outpost, application UUID, and optional daily UTC schedule. Database profiles also need an engine. For **Via Hub**, give the hub a readable folder path or a reachable PostgreSQL/MySQL endpoint and an absolute password-file path. Mount these files into the container when applicable. TLS verifies the server identity by default. Provide a CA file for a private CA. The hub needs a matching database client on its PATH. The bundled hub image includes `pg_dump` and `mysqldump`. Use a compatible client for the source server version. For CLI setup, create an orbit using `tessera orbit billing --provider wormhole` and save its returned UUID. Use the UUID of the paired outpost shown in **Outposts**. Choose a stable application UUID and submit the following object to `POST /api/v1/capture-profiles` using the hub's admin API token or authenticated operator session. ```json { "application_id": "e1656c14-0d87-4572-a548-b66cc283e61f", "orbit_id": "393e5c00-65b8-4084-a521-099732948a6c", "outpost_id": "c7072265-89ab-493a-8dbe-948c1e9aa24c", "format": "postgres_custom", "schedule": { "hour": 2, "timezone": "Asia/Jakarta" } } ``` A schedule is optional. Scheduled jobs catch up from the time the profile was registered and stay queued while the outpost is offline. Retention defaults to 14 days and keeps the newest archive. Use `"retention": {"mode": "count"}` for five archives or set its `keep` value explicitly. An orbit's custom GFS policy applies when the profile has no explicit retention override. The offline CLI decay command only processes legacy snapshots. Set the same application UUID in the agent's local JSON file. Each entry has a `source` and an optional `timeout_seconds` (default 3600). The password file contains one line and should be readable only by the service account. ```json { "e1656c14-0d87-4572-a548-b66cc283e61f": { "source": { "engine": "postgres", "host": "billing.internal", "database": "billing", "user": "backup", "password_file": "/etc/tessera/billing.password", "tls": { "mode": "verify_full_with_ca", "ca_file": "/etc/tessera/database-ca.pem" } } } } ``` | Case | Format | Agent source | | --- | --- | --- | | Direct PostgreSQL | `postgres_custom` or `postgres_sql` | Example above. Port defaults to 5432. TLS defaults to `verify_full`. | | PostgreSQL through SSH | `postgres_custom` or `postgres_sql` | Add a `bastion` object. Keep the PostgreSQL hostname that the server certificate covers. | | Direct MySQL | `mysql_sql` | Use `"engine": "mysql", "transport": "direct"`, host, database, user, password file and MySQL TLS policy. Port defaults to 3306. TLS modes include `verify_identity_with_ca` with a CA file and `required`. | | MySQL through SSH | `mysql_sql` | Use `"engine": "mysql", "transport": "ssh"`, `bastion`, `database` and `defaults_file`. The latter is an absolute path to a private MySQL client options file on the SSH host. | The `bastion` object has `host`, `user`, `identity_file`, `known_hosts_file` and an optional `port` (default 22). Use an absolute path for each file. Record the authorized SSH server host key in the pinned known-hosts file. The SSH login needs forwarding permission for PostgreSQL or permission to run the MySQL client and read its options file for remote MySQL. ## Run and inspect a backup Open **Orbits → Outpost backup jobs**, select an application, and queue a backup. In the API, use `POST /api/v1/capture-profiles/{application-id}/jobs`. Poll `GET /api/v1/capture-jobs/{job-id}` for status and its `/events` endpoint for phase history. The list endpoint supports `application_id`, `status`, and `limit` filters. Successful captures expose their engine, format, and job ID in the snapshot catalog. New Outpost orbits require the current agent and an incremental Restic repository. Follow the Rest Server and repository setup in [the README](../README.md#incremental-wormhole-transfers-for-filesystem-archives) for each orbit. Use the same repository password in the hub's orbit key and the agent's password file. Add these fields to the application's agent profile: ```json { "restic_repository": "rest:https://backup.example.org//", "restic_password_file": "/etc/tessera/keys/repository-password", "rest_server_password_file": "/etc/tessera/keys/rest-server-password" } ``` The Rest Server login is the orbit ID when `rest_server_password_file` is set. For a private Rest Server CA, configure `RESTIC_CACERT` on the agent. A filesystem profile uses `"paths": ["/path/to/folder"]` in place of `source` and `"format": "filesystem"` on the hub. The agent sends new Restic chunks and snapshot metadata. The hub registers the snapshot after checking the lease and repository. One capture job produces one catalog ID across retries. A logical database backup needs room on the executor for one private temporary dump per concurrent capture. A database can run with its normal logging settings. The dump is read in full at the source, and Restic performs deduplication before transfer to the repository. Existing database orbits keep the legacy full-upload path until their Restic repository is configured. That path validates length and SHA-256 at ingest, stages on both sides, and has a 100 GiB upload limit. Use the snapshot detail to download or remove an archive. Database snapshots can also be exported to a file on the hub. Use **Database recovery options** to apply a verified database archive to a registered target. ## Operator sign-in Generate an Argon2id hash and set `TESSERA_OPERATOR_PASSWORD_HASH` to the result. The hub reads the password from stdin in hash mode. For example, from an interactive Bash shell: ```bash read -rs -p 'Operator password: ' tessera_operator_password; printf '\n' export TESSERA_OPERATOR_PASSWORD_HASH="$(printf '%s\n' "$tessera_operator_password" | tessera-hub --hash-operator-password)" unset tessera_operator_password ``` Set `TESSERA_OPERATOR_NAME` for the audited identity, or use the default `operator`. Serve the browser over HTTPS outside loopback. Sessions expire after eight hours or a hub restart. Browser mutations require the session's CSRF token. API and CLI callers use the separate `TESSERA_ADMIN_TOKEN`. Use the bundled HTTP CLI on the hub's loopback listener when sending the token. ## Optional S3 copy Configure `TESSERA_OFFSITE_REPOSITORY=s3:https://s3.example.org/tessera-backups/managed` with a dedicated prefix and point `TESSERA_OFFSITE_PASSWORD_FILE` to the independent Restic password. Supply AWS credentials via the hub service environment or the provider's credential chain. In Docker, mount the password file at the container path using a read-only mount. The hub retries failed copies and reports their state on the capture job. Local retention and deletion protect pending copies. Off-site archives remain available independently after local catalog removal. To recover without the hub or its primary repository, use the off-site Restic password and S3 credentials with these commands: ```sh restic -r "$TESSERA_OFFSITE_REPOSITORY" --password-file "$TESSERA_OFFSITE_PASSWORD_FILE" snapshots --tag "tessera-" restic -r "$TESSERA_OFFSITE_REPOSITORY" --password-file "$TESSERA_OFFSITE_PASSWORD_FILE" dump /payload > recovered.dump ``` ## Register a restore target Configure target credentials on the assigned agent. A target can use a different outpost from its source. PostgreSQL identifies a logical database by cluster system identifier and database name. MySQL uses the server UUID and database name. PostgreSQL source and target roles need read access to `pg_catalog.pg_control_system()` to verify identity. A capture with an unavailable source identity remains available for export. From a restorable snapshot, open **Database recovery options** and select **Register restore target**. For API setup, call `POST /api/v1/restore-targets` with `id`, `application_id`, `outpost_id`, `name`, `engine` and `identity`. The identity has `instance` and `database`. Query the values on the target. - PostgreSQL uses `SELECT system_identifier, current_database() FROM pg_catalog.pg_control_system()`. - MySQL uses `SELECT LOWER(@@server_uuid), DATABASE()`. On the target agent, add a `targets` map under the application UUID, keyed by the registered target UUID. A target-only outpost can omit the application's `source`. An example PostgreSQL entry follows. ```json { "engine": "postgres", "connection": { "host": "staging-db.internal", "database": "billing_staging", "user": "restore", "password_file": "/etc/tessera/staging.password", "tls": { "mode": "verify_full_with_ca", "ca_file": "/etc/tessera/database-ca.pem" } }, "mode": { "reset": "schema", "schema": "public" } } ``` Use `{"reset":"recreate_database"}` to recreate the registered PostgreSQL database. It requires access to the `postgres` maintenance database and permission to drop and create the target database. Schema mode resets the named schema and applies the dump in a transaction. Supply a local `post_restore_sql` file for target-specific SQL. PostgreSQL can read custom archives and plain or gzip-compressed SQL. The agent requires a psql client with restricted mode for restore. `omit_transaction_timeout` and `omit_pg_stat_statements` enable specific compatibility rules. A MySQL target uses `"engine":"mysql"` and the same `connection` fields as a direct or SSH MySQL source. `recreate_database` drops and recreates the registered database before applying SQL. `use_target_definer` rewrites supported dump DEFINER clauses to the connected MySQL user. Choose the snapshot and target in **Restore**. The required confirmation includes both UUIDs. The hub verifies the safety archive before issuing the single-use apply permit. If the job reports `recovery_required`, stop any old apply process and verify its database session has ended. Recover the target with the linked safety archive, verify data and permissions, then confirm reconciliation to release the lock. Session-authenticated file exports use a filename in the hub's private `exports` directory. ## Import legacy archives Run the CLI against the staging vault. Use an AWS CLI profile with `s3:ListBucket` scoped to the legacy prefix and `s3:GetObject` on the objects in that prefix. ```sh tessera legacy-import --bucket legacy-bucket --prefix billing/ --orbit-id ORBIT_UUID --application billing --engine postgres --inventory-only ``` Repeat without `--inventory-only` to import. The JSON report includes the source key, ETag, size, last-modified timestamp, and Tessera snapshot ID. Conditional reads reject changed objects between listing and download. A persistent receipt prevents reimport after local retention and GC. [AWS S3 CLI inventory](https://docs.aws.amazon.com/cli/latest/reference/s3api/list-objects-v2.html), [AWS S3 conditional download](https://docs.aws.amazon.com/cli/latest/reference/s3api/get-object.html). Add `--history /path/to/consistent-history.sqlite` to archive a consistent SQLite export of the old job history. Save the reported history ID and retrieve it with `tessera legacy-history HISTORY_UUID history.sqlite` on the vault host. Inspect the retrieved copy read-only. Legacy SQL archives retain their original bytes and can be applied to a temporary database with the matching engine client.