Start PKI initialization (init-pki, CA, server certificate, DH, TLS key, CRL) as a background job. Returns immediately.
- **Response `202`**: `{"state": "running"}`
- **Response `409`**: a job is already running, or the PKI is already complete (`ca.crt`, `dh.pem`, `ta.key`, `crl.pem` and the server certificate). An incomplete PKI left by an interrupted run is removed and initialization starts again.
- **Note**: Job state is kept in memory; the Profiler must run as a single process (one uvicorn worker). After a restart the state is `idle`.
-`pki_ready`: the PKI is initialized and no job is running (client certificates can be issued).
-`server_ready`: `pki_ready` and every file `server.conf` references exists; `missing` lists the absent ones (relative to the PKI directory: `ca.crt`, `issued/<fqdn_server>.crt`, `private/<fqdn_server>.key`, `dh.pem`, `ta.key`, and `crl.pem` only when `crl_verify` is on). The check uses the current `fqdn_server`, so renaming the server after init makes it not ready.
- **Response `409`**: the PKI is not initialized or an init job is running (`"PKI is not initialized. Initialize PKI first."`), or server files are missing (`"PKI server files are missing: ..."`).
Guide: [Backup and Restore](Backup_Restore.md). All routes need the JWT. Errors: `400` invalid request, `409` another job is running (or a restore is running), `502` the destination could not be reached. Messages never contain secrets.
While a restore runs, `POST /profiles`, `DELETE /profiles/{id}`, `PUT /profiles/{id}/note`, `PUT /config/*`, `POST /system/init`, `DELETE /system/pki`, `POST /server/configure` and `POST /server/process/{action}` return `409` (`"A backup restore is running"`).
| Method | Path | Purpose |
|---|---|---|
| GET, PUT | `/backup/settings` | encryption flag and passphrase, server name, default retention, local root, the implemented destination types with their fields |
| GET, POST | `/backup/destinations` | list, create (`201`) |
- **GET response**: `{"encryption_enabled": true, "default_retention": 14, "server_name": "vpn-main", "effective_server_name": "vpn-main", "server_name_source": "setting", "local_root": "/app/backups", "types": [{"id": "local", "label": "...", "remote": false, "pins_host_key": false, "fields": [...]}, ...]}`. The passphrase is never returned. `server_name` is the configured name (`""` when none); `effective_server_name` is the name used in package names and `server_name_source` says where it comes from: `setting`, `public_ip` (the address of the VPN settings) or `hostname`. A field of `fields` has `name`, `label`, `kind` (`text`, `number`, `bool`, `secret`, `secret_multiline`), `required`, `default`, optional `hint` and `warning` + `warn_if` (the warning applies while the value equals `warn_if`).
- **PUT body**: `{"passphrase": "..."}` (at least 8 characters) sets or changes it; `{"clear_passphrase": true}` removes it (`400` while an enabled remote destination exists); `{"default_retention": 14}`; `{"server_name": "vpn-main"}` (`^[A-Za-z0-9][A-Za-z0-9.-]{0,62}$`, else `400`; `""` clears it).
### Destinations
- **Body (POST, PUT)**: `{"name": "offsite", "type": "s3", "enabled": true, "retention_count": 14, "params": {...}, "secrets": {...}}`. `type` must be an implemented one (`local`, `s3`, `sftp`, `ftp`), otherwise `400`.
-`local`: `params: {"folder": "daily"}`, no secrets.
-`sftp`: `params: {"host": "files.example.com", "port": 22, "username": "backup", "directory": "ovpmon/daily"}`, `secrets: {"password": "..."}`**or**`{"private_key": "<key text>", "key_passphrase": "..."}` (not both). `params` also carries `host_key` and `host_key_type` once a key is trusted; they are set only by `trust-host-key` (ignored in the body, kept on `PUT` while `host` and `port` stay the same, cleared when one of them changes).
-`directory` (SFTP, FTP): relative, letters, digits, `.`, `_`, `-`, no `..`, at most 4 levels.
- **Response**: the destination with `secrets` masked (`"********"` for each secret that is set), `last_status`, `last_message`, `last_at`. On `PUT`, a secret that is missing, empty or `"********"` keeps the stored value.
- **Test response**: `{"ok": true, "message": "..."}` (`ok: false` carries the reason). For an SFTP destination whose host key is not trusted (or changed): `{"ok": false, "message": "...", "needs_trust": true, "fingerprint": "SHA256:...", "key_type": "ssh-ed25519", "key_changed": false}`.
- **Body**: `{"fingerprint": "SHA256:..."}`: the one shown by Test. The server connects again (no credentials are sent) and pins the key only if it shows exactly that fingerprint; otherwise `400` ("run Test again"). Allowed for `sftp` destinations only (`400` otherwise); `409` while a job runs; `502` when the server cannot be reached.
- **Response**: the updated destination (`params.host_key` set).
- Until a key is trusted, SFTP backup, listing, restore and delete are refused (`502`, "The host key of the server is not trusted yet"); on a mismatch the connection is refused.
### `GET /backup/destinations/{id}/packages`
- **Response**: `{"packages": [{"name": "ovpmon-backup_vpn-main_20261007T101500Z.ovpbak.enc", "server_name": "vpn-main", "created_at": "2026-10-07T10:15:00Z", "size": 123456, "encrypted": true}]}`, newest first (time, then the `-2`, `-3` suffix). `created_at` is UTC and comes from the file name. `502` when the source cannot be read.
### `POST /backup/run`
- **Body (optional)**: `{"destination_ids": [1, 2]}`; without it all enabled destinations are used.
- **Response `400`**: nothing selected, a disabled destination, or a remote destination without a passphrase.
### `POST /backup/restore`
- **Body**: `{"destination_id": 1, "package": "<name from the listing>", "passphrase": "..."}`. The name is checked against the pattern and must be in the destination's listing; paths are never accepted. The passphrase is required for `.enc` packages.
- **Response `409`**: a job or an initialization of the PKI is running.
- Backup stages: `package`, `encrypt` (only with a passphrase), `upload`. Restore stages: `download`, `decrypt`, `verify`, `prepare`, `safety_backup`, `stop_openvpn`, `replace`, `finalize`. `partial`: stored in some destinations only. `relogin` is true after a successful restore. The state is kept in memory (single Profiler process); the history is kept in `ovpmon_backup.db`.