From 10466416df87995779e1133e4dd55704103a89f8 Mon Sep 17 00:00:00 2001 From: Ilker Manap Date: Sun, 4 Oct 2026 23:09:59 +0200 Subject: [PATCH] =?UTF-8?q?server=20restore:=20an=20archive=20checked,=20d?= =?UTF-8?q?ry-run,=20and=20put=20back=20=E2=80=94=20configuration=20with?= =?UTF-8?q?=20modes=20and=20owners,=20the=20store=20in=20SQLite=20or=20Pos?= =?UTF-8?q?tgreSQL;=20backup=5Fcopy=5Fto=20copies=20archives=20off=20the?= =?UTF-8?q?=20machine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 (1M context) --- BACKLOG.md | 8 +- CHANGELOG.md | 14 + docs/install.md | 66 ++-- docs/reference.md | 19 ++ internal/cli/backup.go | 31 +- internal/cli/backupcopy.go | 84 +++++ internal/cli/restore.go | 546 +++++++++++++++++++++++++++++++ internal/cli/restore_test.go | 118 +++++++ internal/cli/server.go | 2 +- internal/config/config.go | 24 ++ internal/docgen/reference_gen.go | 2 + 11 files changed, 889 insertions(+), 25 deletions(-) create mode 100644 internal/cli/backupcopy.go create mode 100644 internal/cli/restore.go create mode 100644 internal/cli/restore_test.go diff --git a/BACKLOG.md b/BACKLOG.md index 6ae5f0d..3b46c91 100644 --- a/BACKLOG.md +++ b/BACKLOG.md @@ -465,7 +465,13 @@ portal is not done — the page shows; the console and ctl change. thinking blocks); prompt caching; the account page's "Connect your editor" does not offer Claude Code yet. **Anthropic `/v1/messages` (M).** Translate like `responses.go`. -12. **`server restore` (S).** Restore is manual shell today +12. **Done (branch `features-c2`):** `server restore` (dry run, version + check, decryption, modes and owners, SQLite and PostgreSQL), + `backup_copy_to` (directory or ssh), the drill in docs/install.md. + Left: restoring a replicated store's members (restore into the primary; + Patroni replicates it); the console's Back up now does not offer + restore; an ssh copy holds the archive in memory while it sends it. + **`server restore` (S).** Restore is manual shell today (`docs/install.md:1187`); add the command with version check, dry run, off-host copy target; a documented DR drill. 13. **SLO-based admission and token-level metrics (S–M).** TPOT and diff --git a/CHANGELOG.md b/CHANGELOG.md index 21d1683..0b537b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,6 +71,20 @@ APIs change between minors without a deprecation period. - **Other ways in:** `GET /api/v1/usage/export` (CSV, or `format=json`) and **E** on the console's Usage view. +### Restoring a backup, and copies off the machine + +- **`llmgw server restore ARCHIVE`** puts a backup back: checks it first + (whole, opens with `--identity`, not newer than this llmgw, where the store + goes), says so with `--dry-run`, then moves `/etc/llmgw` aside, restores it + with modes and owners, restores the store (SQLite, or PostgreSQL with + `pg_restore --clean`), and starts the server. A drill is in + docs/install.md. +- **`backup_copy_to`** copies each archive to a directory or over ssh as it + is written, keeping as many there as here; refused without + `backup_recipients`. +- Archives now record each file's owner by name, so a restore on another + machine gives the llmgw user its files back. + ### Anthropic's Messages API - **`/v1/messages`** (and `/v1/messages/count_tokens`) translated to chat diff --git a/docs/install.md b/docs/install.md index ba2615e..aaf8fdc 100644 --- a/docs/install.md +++ b/docs/install.md @@ -1529,35 +1529,63 @@ anywhere else.** Restoring an old store restores which keys exist and who owns them, not their secrets. A key created after the backup is gone and has to be reissued. +### Copying archives off the machine + +```yaml +backup_recipients: [age1…] # required: an archive leaves only encrypted +backup_copy_to: + - /mnt/backups/llmgw # a mounted share or another disk + - ssh://backup@10.0.0.20/srv/llmgw-backups +backup_copy_key: /etc/llmgw/secrets/backup-ssh-key +``` + +Each archive is copied there as soon as it is written, and the same number is +kept there as here (`--keep`, 14). An ssh host's key is learnt the first time +and checked every time after, in `/etc/llmgw/backup_known_hosts`. A copy that +fails makes the backup fail, so the timer's unit shows it. + ### Restoring -On a machine with llmgw installed (the same version or newer) and, for -PostgreSQL, an empty database and role as `server init --postgres` would create -them: +On a machine with llmgw installed — the same version as the archive's, or +newer — and, for PostgreSQL, the database and role the store's address names: ``` -sudo systemctl stop llmgw-server -mkdir /tmp/restore && sudo tar -xzf /var/backups/llmgw-server/llmgw-backup--