home-hosted 0.9.4 → 0.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,128 @@
1
+ # Blank-host restore, with a database
2
+
3
+ A worked example: one home stack backed up on one machine, restored onto a machine that starts with
4
+ nothing, and the database read back afterwards.
5
+
6
+ Every command below is real. The whole thing is a script you can run:
7
+ [`blank-host-restore.sh`](./demo/blank-host-restore.sh). It uses throwaway directories under `$TMPDIR` and
8
+ docker containers it removes on exit, so it touches nothing of yours.
9
+
10
+ ```sh
11
+ docs/demo/blank-host-restore.sh
12
+ ```
13
+
14
+ ## The stack
15
+
16
+ One entry: a MongoDB container, with a database dump declared as its data.
17
+
18
+ ```json
19
+ {
20
+ "id": "blog-db",
21
+ "command": "docker",
22
+ "args": ["run", "--rm", "--name", "hh-demo-blog", "-p", "27017:27017", "mongo:7"],
23
+ "port": 27017,
24
+ "backupPaths": ["/srv/blog/dump"]
25
+ }
26
+ ```
27
+
28
+ `backupPaths` is the important field. It names what belongs to this entry **beyond** its config, and
29
+ that is what the archive carries.
30
+
31
+ ## Backing it up
32
+
33
+ ```console
34
+ $ home-hosted backup create
35
+ backup created backup-2026-10-21-04-15-49-881.zip (4 KB)
36
+
37
+ $ home-hosted backup list
38
+ 1 archive in /home/you/.home-hosted/.hh/.backups
39
+ backup-2026-10-21-04-15-49-881.zip 4 KB 2026-10-21 04:15
40
+ ```
41
+
42
+ The archive is a plain zip. Its contents, in full:
43
+
44
+ ```text
45
+ data/
46
+ data/srv-blog-dump/
47
+ data/srv-blog-dump/blog.archive <- the database dump
48
+ global/
49
+ global/secrets.json <- password hash, API token hash
50
+ global/settings.json <- listener, TLS policy, host vitals, proxy
51
+ global/workspaces.json <- the registry: what workspaces exist
52
+ manifest.json <- what release wrote it, and the schema it understood
53
+ workspaces/
54
+ workspaces/default/
55
+ workspaces/default/servers.config.json
56
+ workspaces/default/settings.json
57
+ ```
58
+
59
+ **The dump is the data.** `backupPaths` pointed at a directory holding `mongodump` output, not at
60
+ MongoDB's live data directory. That distinction matters: copying a running database's files can
61
+ capture it torn, which [`README.md`](../README.md#-backups) warns about. A dump is consistent by
62
+ construction.
63
+
64
+ ## Restoring onto a blank host
65
+
66
+ ```console
67
+ $ home-hosted backup restore backup-2026-10-21-04-15-49-881.zip
68
+ Plan for backup-2026-10-21-04-15-49-881.zip — nothing has been written yet
69
+ settings global:settings
70
+ secrets global:secrets
71
+ secrets global:secrets:password
72
+ secrets global:secrets:apiToken
73
+ settings workspace:default:settings
74
+ servers workspace:default:servers
75
+ data workspace:default:data:/srv/blog/dump
76
+
77
+ apply it with `home-hosted backup restore backup-2026-10-21-04-15-49-881.zip --confirm`
78
+ ```
79
+
80
+ The plan comes first, always. A restore writes over live data, so the default is to say what it
81
+ *would* do.
82
+
83
+ ```console
84
+ $ home-hosted backup restore backup-2026-10-21-04-15-49-881.zip --confirm
85
+ restored 7 items from backup-2026-10-21-04-15-49-881.zip
86
+ ```
87
+
88
+ The workspace did not exist on this host. It was created, not skipped: an archive is a whole machine's
89
+ setup, and refusing it because the id is new would make a blank-host restore impossible.
90
+
91
+ Then the entry starts, and the database is read back:
92
+
93
+ ```console
94
+ $ home-hosted start blog-db
95
+ started blog-db
96
+
97
+ $ docker exec hh-demo-blog mongosh --quiet --eval 'db.getSiblingDB("blog").posts.countDocuments()'
98
+ 0
99
+
100
+ $ docker exec hh-demo-blog mongorestore --archive=/srv/blog/dump/blog.archive --drop
101
+ $ docker exec hh-demo-blog mongosh --quiet --eval 'db.getSiblingDB("blog").posts.countDocuments()'
102
+ 3
103
+ ```
104
+
105
+ Three documents, on a host that started with nothing.
106
+
107
+ ## What is recovered, and what is not
108
+
109
+ | | |
110
+ | --- | --- |
111
+ | ✅ **Recovered** | Every workspace and its label. Every entry, with its command, args, env, port and policies. Workspace settings: notifications, DDNS, log retention, server defaults. Panel settings: listener, TLS policy, host vitals, backup schedule, proxy routes. Secrets, if you kept them ticked. Declared data paths, including the database dump. |
112
+ | ⚠️ **Recovered, then you must act** | The **password hash and API token hash** travel in `global/secrets.json`, so the restored host has the old machine's credentials. Anyone holding that token still has access. Rotate with `home-hosted set-token --generate`, or exclude those secrets and set them fresh. |
113
+ | ⚠️ **Recovered, but the database needs its own step** | The panel restores **files**, not databases. It puts `blog.archive` back where it was; applying it is `mongorestore` (or `pg_restore`, `.restore`, whatever your engine calls it). That is deliberate: only the engine knows how to apply its own dump. |
114
+ | ❌ **Not recovered** | `HHOSTED_DDNS_SECRET`, the key DDNS credentials are sealed under. It is never archived, so a restored host cannot decrypt them until you set it again. |
115
+ | ❌ **Not recovered** | Anything not in a `backupPaths` directory or the panel's own state: files your entries wrote elsewhere, host packages, `/etc` changes, a reverse proxy outside the panel, cron jobs, the docker images themselves. |
116
+ | ❌ **Not recovered** | The UI you had installed, if it was not the stock one. An official UI is fetched again on the next `up`. |
117
+
118
+ ## Re-running it
119
+
120
+ The script is the reproducible form of everything above:
121
+
122
+ ```sh
123
+ docs/demo/blank-host-restore.sh
124
+ ```
125
+
126
+ It creates two state directories, seeds a real MongoDB, dumps it, backs it up, restores onto the
127
+ blank second host, starts the entry there and asserts the documents came back. It exits non-zero if
128
+ they do not.
@@ -147,7 +147,7 @@ naming one that does not exist is a `404 UNKNOWN_WORKSPACE`, never a silent fall
147
147
  | `PUT` / `DELETE /api/notifications/destinations/:id/token`, `POST /api/notifications/destinations/:id/{test,detect-chats}`, `POST /api/notifications/test-webhook` | one destination's bot credential and a test send, per workspace |
148
148
  | `GET` / `PUT /api/ddns`, `PUT` / `DELETE /api/ddns/credentials/:id`, `POST /api/ddns/check` | dynamic DNS, per workspace: the policy plus live per-record state, one account's sealed credentials (write-only — the view exposes ids and whether each is set, never the values), and a pass run now |
149
149
  | `POST /api/auth/login`, `GET /api/auth/session`, `POST /api/auth/logout` | the session |
150
- | `GET /healthz` | liveness — **no session**, and `503` when a server has crashed or a running one is failing its health check |
150
+ | `GET /healthz` | liveness — **no session**, and `503` when a server has crashed, when the panel stopped one because it could not serve, or while a running one is failing its health check |
151
151
  | `GET /api/metrics` | Prometheus text (needs a session) |
152
152
 
153
153
  `GET /healthz` and `GET /openapi/*` are the only unauthenticated reads; the SPA shell itself is
@@ -0,0 +1,192 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # A blank-host backup/restore demo, with a real database.
4
+ #
5
+ # Two hosts, one after the other, in throwaway directories:
6
+ #
7
+ # 1. host A — a panel with one entry (a MongoDB container) and some data in it
8
+ # 2. take a backup: `home-hosted backup create`
9
+ # 3. host B — a *blank* home, nothing configured
10
+ # 4. restore into it: `home-hosted backup restore <name> --confirm`
11
+ # 5. start the entry on host B and read the database back
12
+ #
13
+ # Every step is a real command against a real panel and a real container. Nothing is faked, and the
14
+ # script fails loudly rather than continuing on a wrong assumption.
15
+ #
16
+ # Usage: docs/demo/blank-host-restore.sh
17
+ # Requires: docker, pnpm, node 24. Runs entirely under $TMPDIR; touches nothing of yours.
18
+
19
+ set -euo pipefail
20
+
21
+ REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
22
+ WORK="$(mktemp -d "${TMPDIR:-/tmp}/hh-demo-XXXXXX")"
23
+ HOST_A="$WORK/host-a"
24
+ HOST_B="$WORK/host-b"
25
+ DATA="$WORK/blog"
26
+ MONGO="hh-demo-mongo"
27
+ APP="hh-demo-blog"
28
+ PANEL_A=6470
29
+ PANEL_B=6471
30
+ CLI=(pnpm --dir "$REPO" exec tsx src/cli.ts)
31
+
32
+ say() { printf '\n\033[1m%s\033[0m\n' "$*"; }
33
+ note() { printf ' %s\n' "$*"; }
34
+
35
+ cleanup() {
36
+ docker rm -f "$APP" "$MONGO" >/dev/null 2>&1 || true
37
+ HHOSTED_HOME="$HOST_A" "${CLI[@]}" down >/dev/null 2>&1 || true
38
+ HHOSTED_HOME="$HOST_B" "${CLI[@]}" down >/dev/null 2>&1 || true
39
+ rm -rf "$WORK"
40
+ }
41
+ trap cleanup EXIT
42
+
43
+ # ---------------------------------------------------------------------------- host A
44
+
45
+ say "Host A: a blank machine with one stack"
46
+
47
+ mkdir -p "$DATA/dump"
48
+ docker run -d --name "$MONGO" -p 27017:27017 mongo:7 >/dev/null
49
+ note "started $MONGO"
50
+
51
+ # Wait for it to accept connections, rather than sleeping and hoping.
52
+ for _ in $(seq 1 60); do
53
+ docker exec "$MONGO" mongosh --quiet --eval 'db.runCommand({ping:1}).ok' >/dev/null 2>&1 && break
54
+ sleep 1
55
+ done
56
+
57
+ docker exec "$MONGO" mongosh --quiet --eval '
58
+ db.getSiblingDB("blog").posts.insertMany([
59
+ { title: "How I stopped using tmux", slug: "tmux" },
60
+ { title: "One panel for six services", slug: "panel" },
61
+ { title: "Backups that survive a dead disk", slug: "backups" },
62
+ ])
63
+ ' >/dev/null
64
+ note "seeded 3 documents into blog.posts"
65
+
66
+ # The dump, not the live files. A running database's data directory copied file by file can be torn,
67
+ # which the README warns about; `mongodump --archive` is the consistent artifact.
68
+ docker exec "$MONGO" mongodump --db blog --archive=/tmp/blog.archive --quiet
69
+ docker cp "$MONGO:/tmp/blog.archive" "$DATA/dump/blog.archive" >/dev/null
70
+ note "dumped the database to $DATA/dump/blog.archive"
71
+
72
+ mkdir -p "$HOST_A"
73
+ HHOSTED_HOME="$HOST_A" "${CLI[@]}" up --port "$PANEL_A" --no-autostart >/dev/null
74
+ TOKEN_A="$(HHOSTED_HOME="$HOST_A" "${CLI[@]}" set-token --generate | grep -oE 'hh_[A-Za-z0-9_-]+' | head -1)"
75
+ note "panel on :$PANEL_A"
76
+
77
+ # An entry whose `backupPaths` names the dump, and whose port lets the panel health-check it.
78
+ curl -fsS -o /dev/null -X POST \
79
+ -H "Authorization: Bearer $TOKEN_A" -H 'content-type: application/json' \
80
+ -d "{
81
+ \"id\": \"blog-db\",
82
+ \"command\": \"docker\",
83
+ \"args\": [\"run\", \"--rm\", \"--name\", \"$APP\", \"-p\", \"27017:27017\", \"mongo:7\"],
84
+ \"port\": 27017,
85
+ \"backupPaths\": [\"$DATA/dump\"]
86
+ }" \
87
+ "http://127.0.0.1:$PANEL_A/api/servers?workspace=default"
88
+ note "declared the entry: docker run mongo:7, backupPaths = $DATA/dump"
89
+
90
+ # ---------------------------------------------------------------------------- the backup
91
+
92
+ say "Taking a backup"
93
+
94
+ HHOSTED_HOME="$HOST_A" "${CLI[@]}" backup create
95
+ ARCHIVE="$(HHOSTED_HOME="$HOST_A" "${CLI[@]}" backup list --json | node -e '
96
+ let raw = ""
97
+ process.stdin.on("data", chunk => raw += chunk)
98
+ process.stdin.on("end", () => {
99
+ const view = JSON.parse(raw)
100
+ process.stdout.write(view.files[0].name)
101
+ })
102
+ ')"
103
+ note "archive: $ARCHIVE"
104
+
105
+ # Host A is gone, which is the premise of the whole exercise. Its container has to go with it, or
106
+ # the port is still held when host B tries to start the restored entry.
107
+ docker rm -f "$MONGO" >/dev/null 2>&1 || true
108
+ note "stopped host A's container (host A is gone, after all)"
109
+
110
+ say "What is in the archive"
111
+ node -e '
112
+ const { execFileSync } = require("node:child_process")
113
+ const out = execFileSync("unzip", ["-Z1", process.argv[1]], { encoding: "utf8" })
114
+ for (const line of out.trim().split("\n")) console.log(" " + line)
115
+ ' "$HOST_A/.hh/.backups/$ARCHIVE" 2>/dev/null || note "(unzip not installed; skipping the listing)"
116
+
117
+ # ---------------------------------------------------------------------------- host B
118
+
119
+ say "Host B: a blank machine, nothing configured"
120
+
121
+ mkdir -p "$HOST_B"
122
+ if [ -e "$HOST_B/.hh/workspaces.json" ]; then
123
+ note "unexpected: host B is not blank"; exit 1
124
+ fi
125
+ note "$HOST_B has no .hh at all"
126
+
127
+ HHOSTED_HOME="$HOST_B" "${CLI[@]}" up --port "$PANEL_B" --no-autostart >/dev/null
128
+ # A token to authorise the upload. The archive carries host A's `secrets.json`, so this one is
129
+ # replaced by the restore and a fresh one is minted afterwards.
130
+ SETUP_TOKEN="$(HHOSTED_HOME="$HOST_B" "${CLI[@]}" set-token --generate | grep -oE 'hh_[A-Za-z0-9_-]+' | head -1)"
131
+ note "panel on :$PANEL_B"
132
+
133
+ # The archive travels as a file, which is the whole point: one artifact to move.
134
+ cp "$HOST_A/.hh/.backups/$ARCHIVE" "$WORK/$ARCHIVE"
135
+
136
+ # The plan first, always: a restore writes over live data, so the default is to say what it would do.
137
+ say "Planning the restore (nothing is written yet)"
138
+ mkdir -p "$HOST_B/.hh/.backups"
139
+ cp "$WORK/$ARCHIVE" "$HOST_B/.hh/.backups/$ARCHIVE"
140
+ HHOSTED_HOME="$HOST_B" "${CLI[@]}" backup restore "$ARCHIVE"
141
+ rm -f "$HOST_B/.hh/.backups/$ARCHIVE"
142
+ curl -fsS -o /dev/null -X POST \
143
+ -H "Authorization: Bearer $SETUP_TOKEN" \
144
+ -F "file=@$WORK/$ARCHIVE" \
145
+ "http://127.0.0.1:$PANEL_B/api/backups/restore?confirm=true"
146
+ note "uploaded and restored onto the blank host"
147
+
148
+ # The archive carried host A's `global/secrets.json`, so host B now has host A's password hash and
149
+ # API token hash — the archive is the whole machine's identity, not just its entries. The README
150
+ # warns about exactly this. A real move should either accept that or rotate afterwards; this demo
151
+ # rotates, because a token that travelled in an archive is a token in a file.
152
+ TOKEN_B="$(HHOSTED_HOME="$HOST_B" "${CLI[@]}" set-token --generate | grep -oE 'hh_[A-Za-z0-9_-]+' | head -1)"
153
+ note "rotated host B's API token (the archive had brought host A's)"
154
+
155
+ say "What host B now has"
156
+ HHOSTED_HOME="$HOST_B" "${CLI[@]}" status
157
+
158
+ # ---------------------------------------------------------------------------- prove it serves
159
+
160
+ say "Starting the restored entry"
161
+
162
+ START_ANSWER="$(curl -sS -X POST -H "Authorization: Bearer $TOKEN_B" \
163
+ "http://127.0.0.1:$PANEL_B/api/servers/blog-db/start?workspace=default")"
164
+ node -e 'const a = JSON.parse(process.argv[1]); if (a.ok !== true) { console.error(" start refused: " + (a.message ?? a.error ?? JSON.stringify(a))); process.exit(1) }' "$START_ANSWER"
165
+
166
+ for _ in $(seq 1 60); do
167
+ docker exec "$APP" mongosh --quiet --eval 'db.runCommand({ping:1}).ok' >/dev/null 2>&1 && break
168
+ sleep 1
169
+ done
170
+
171
+ say "Reading the database on the restored host"
172
+
173
+ docker cp "$DATA/dump/blog.archive" "$APP:/tmp/blog.archive"
174
+ BEFORE="$(docker exec "$APP" mongosh --quiet --eval 'db.getSiblingDB("blog").posts.countDocuments()')"
175
+ note "documents in blog.posts before applying the dump: $BEFORE — the container is fresh, so it is empty"
176
+
177
+ # The dump is the data; restoring the *panel* brought back the entry and the dump beside it. Applying
178
+ # the dump is the database's own step, and this is it.
179
+ docker exec "$APP" mongorestore --archive=/tmp/blog.archive --quiet --drop
180
+ COUNT="$(docker exec "$APP" mongosh --quiet --eval 'db.getSiblingDB("blog").posts.countDocuments()')"
181
+ TITLES="$(docker exec "$APP" mongosh --quiet --eval 'db.getSiblingDB("blog").posts.find({}, {title:1, _id:0}).toArray().map(p => p.title).join(" | ")')"
182
+
183
+ say "Result"
184
+ note "blog.posts documents: $COUNT"
185
+ note "titles: $TITLES"
186
+
187
+ if [ "$COUNT" = "3" ]; then
188
+ printf '\n\033[32mrestored: the same 3 documents, on a host that started blank\033[0m\n'
189
+ else
190
+ printf '\n\033[31mFAILED: expected 3 documents, got %s\033[0m\n' "$COUNT"
191
+ exit 1
192
+ fi
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "home-hosted",
3
3
  "type": "module",
4
- "version": "0.9.4",
4
+ "version": "0.9.5",
5
5
  "packageManager": "pnpm@12.5.1",
6
6
  "description": "Self-hosted control panel that keeps your home-server processes alive: supervision, restarts, port conflicts, logs — and a UI you can replace.",
7
7
  "author": "NamesMT <dangquoctrung123@gmail.com>",
@@ -59,11 +59,13 @@
59
59
  "dist",
60
60
  "docs/DDNS.md",
61
61
  "docs/NOTIFICATIONS.md",
62
+ "docs/RESTORE_DEMO.md",
62
63
  "docs/REVERSE_PROXY.md",
63
64
  "docs/SERVERS.md",
64
65
  "docs/UI_CREATION.md",
65
66
  "docs/branding/logo.svg",
66
67
  "docs/branding/social-preview.png",
68
+ "docs/demo/blank-host-restore.sh",
67
69
  "uis/stock/dist"
68
70
  ],
69
71
  "engines": {
@@ -3,6 +3,6 @@
3
3
  "version": "2.19.8",
4
4
  "repo": "NamesMT/home-hosted",
5
5
  "asset": "home-hosted-ui-stock.zip",
6
- "tag": "v0.9.4",
7
- "unix": 1792521241
6
+ "tag": "v0.9.5",
7
+ "unix": 1792559823
8
8
  }