home-hosted 0.9.4 → 0.9.6
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.
- package/AGENTS.md +7 -6
- package/README.md +8 -1
- package/dist/cli.js +833 -31
- package/dist/cli.js.map +1 -1
- package/docs/RESTORE_DEMO.md +212 -0
- package/docs/UI_CREATION.md +1 -1
- package/docs/demo/blank-host-restore.sh +194 -0
- package/package.json +9 -9
- package/uis/stock/dist/ui.json +2 -2
|
@@ -0,0 +1,212 @@
|
|
|
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
|
+
`create` plans first. That listing is what the archive *would* contain, and nothing has been written
|
|
34
|
+
yet:
|
|
35
|
+
|
|
36
|
+
```console
|
|
37
|
+
$ home-hosted backup create --all
|
|
38
|
+
Plan — what a backup would capture; nothing has been written yet
|
|
39
|
+
settings global:settings
|
|
40
|
+
secrets global:secrets
|
|
41
|
+
- global:secrets:password
|
|
42
|
+
- global:secrets:apiToken
|
|
43
|
+
tls global:tls (does not exist yet)
|
|
44
|
+
workspace workspace:default
|
|
45
|
+
- workspace:default:settings
|
|
46
|
+
- workspace:default:servers
|
|
47
|
+
- workspace:default:data:/srv/blog/dump
|
|
48
|
+
|
|
49
|
+
Take this backup? [y/N] y
|
|
50
|
+
|
|
51
|
+
$ home-hosted backup list
|
|
52
|
+
1 archive in /home/you/.home-hosted/.hh/.backups
|
|
53
|
+
backup-2026-10-21-04-15-49-881.zip 4 KB 2026-10-21 04:15
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`--all` is required: a scope is never assumed, so `backup create` with neither flag refuses and
|
|
57
|
+
lists what could be picked. `--confirm` skips the prompt, which is what a cron job wants. `--json` prints the same plan as JSON
|
|
58
|
+
and never applies, so a script or an agent can read it and decide.
|
|
59
|
+
|
|
60
|
+
### Working while the panel is stopped
|
|
61
|
+
|
|
62
|
+
`backup` does not need the panel. It drives the same service either way, so a stopped panel is fine —
|
|
63
|
+
which is the point, since stopping the services is what someone does before a careful backup or a
|
|
64
|
+
migration:
|
|
65
|
+
|
|
66
|
+
```console
|
|
67
|
+
$ home-hosted down
|
|
68
|
+
$ home-hosted backup create --all --confirm
|
|
69
|
+
backup created backup-2026-10-21-06-55-40-147.zip (3 KB)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
A **persistent** entry keeps running when the panel stops, so "panel off" is not "services off". Those
|
|
73
|
+
are named before the backup is taken, and it proceeds anyway — refusing would block the migration this
|
|
74
|
+
exists for:
|
|
75
|
+
|
|
76
|
+
```console
|
|
77
|
+
$ home-hosted backup create --all
|
|
78
|
+
Plan — what a backup would capture; nothing has been written yet
|
|
79
|
+
...
|
|
80
|
+
! 1 entry is still running (gitea) — its data may be captured mid-write
|
|
81
|
+
|
|
82
|
+
Take this backup? [y/N]
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
One limit: a project started with `up --config <file>` reads that file only while the panel runs. The
|
|
86
|
+
flag is not written to any record, so an offline `backup` reads the default workspace's
|
|
87
|
+
`servers.config.json` and would miss it — start the panel first for that shape.
|
|
88
|
+
|
|
89
|
+
A restore writes a **lock** (`<state>/.hh/restore.lock`), taken by the service itself — so the panel's
|
|
90
|
+
own restore and this one exclude each other, and neither two shells nor a shell and the page can write
|
|
91
|
+
the same host at once. A lock left by a process that died is taken over; one held by a live process
|
|
92
|
+
names it and stops. A dry run takes none, because it writes nothing.
|
|
93
|
+
|
|
94
|
+
### Narrowing what an archive carries
|
|
95
|
+
|
|
96
|
+
`--include` takes the ids from the plan, comma-separated:
|
|
97
|
+
|
|
98
|
+
```console
|
|
99
|
+
$ home-hosted backup create --include workspace:default:servers,global:settings
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`--all` is the only way to say "everything" — giving **neither** flag is refused, not assumed, so the
|
|
103
|
+
destructive default cannot be reached by silence:
|
|
104
|
+
|
|
105
|
+
```console
|
|
106
|
+
$ home-hosted backup create --confirm
|
|
107
|
+
error name what to act on — pass --include <ids> or --all
|
|
108
|
+
|
|
109
|
+
available:
|
|
110
|
+
global:settings
|
|
111
|
+
global:secrets
|
|
112
|
+
workspace:default
|
|
113
|
+
workspace:default:data:/srv/blog/dump
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
An empty `--include` is refused too, rather than treated as "nothing selected" — a script passing an
|
|
117
|
+
unset `$LIST` gets an error instead of quietly backing up (or restoring) the whole machine:
|
|
118
|
+
|
|
119
|
+
```console
|
|
120
|
+
$ home-hosted backup create --include "$UNSET"
|
|
121
|
+
error --include is empty — name the ids to act on, or pass --all for everything
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
`--include` and `--all` together is also refused, since one of them would silently win.
|
|
125
|
+
|
|
126
|
+
The archive is a plain zip. Its contents, in full:
|
|
127
|
+
|
|
128
|
+
```text
|
|
129
|
+
data/
|
|
130
|
+
data/srv-blog-dump/
|
|
131
|
+
data/srv-blog-dump/blog.archive <- the database dump
|
|
132
|
+
global/
|
|
133
|
+
global/secrets.json <- password hash, API token hash
|
|
134
|
+
global/settings.json <- listener, TLS policy, host vitals, proxy
|
|
135
|
+
global/workspaces.json <- the registry: what workspaces exist
|
|
136
|
+
manifest.json <- what release wrote it, and the schema it understood
|
|
137
|
+
workspaces/
|
|
138
|
+
workspaces/default/
|
|
139
|
+
workspaces/default/servers.config.json
|
|
140
|
+
workspaces/default/settings.json
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**The dump is the data.** `backupPaths` pointed at a directory holding `mongodump` output, not at
|
|
144
|
+
MongoDB's live data directory. That distinction matters: copying a running database's files can
|
|
145
|
+
capture it torn, which [`README.md`](../README.md#-backups) warns about. A dump is consistent by
|
|
146
|
+
construction.
|
|
147
|
+
|
|
148
|
+
## Restoring onto a blank host
|
|
149
|
+
|
|
150
|
+
```console
|
|
151
|
+
$ home-hosted backup restore backup-2026-10-21-04-15-49-881.zip
|
|
152
|
+
Plan for backup-2026-10-21-04-15-49-881.zip — nothing has been written yet
|
|
153
|
+
settings global:settings
|
|
154
|
+
secrets global:secrets
|
|
155
|
+
secrets global:secrets:password
|
|
156
|
+
secrets global:secrets:apiToken
|
|
157
|
+
settings workspace:default:settings
|
|
158
|
+
servers workspace:default:servers
|
|
159
|
+
data workspace:default:data:/srv/blog/dump
|
|
160
|
+
|
|
161
|
+
apply it with `home-hosted backup restore backup-2026-10-21-04-15-49-881.zip --confirm`
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
The plan comes first, always. A restore writes over live data, so the default is to say what it
|
|
165
|
+
*would* do.
|
|
166
|
+
|
|
167
|
+
```console
|
|
168
|
+
$ home-hosted backup restore backup-2026-10-21-04-15-49-881.zip --confirm
|
|
169
|
+
restored 7 items from backup-2026-10-21-04-15-49-881.zip
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
The workspace did not exist on this host. It was created, not skipped: an archive is a whole machine's
|
|
173
|
+
setup, and refusing it because the id is new would make a blank-host restore impossible.
|
|
174
|
+
|
|
175
|
+
Then the entry starts, and the database is read back:
|
|
176
|
+
|
|
177
|
+
```console
|
|
178
|
+
$ home-hosted start blog-db
|
|
179
|
+
started blog-db
|
|
180
|
+
|
|
181
|
+
$ docker exec hh-demo-blog mongosh --quiet --eval 'db.getSiblingDB("blog").posts.countDocuments()'
|
|
182
|
+
0
|
|
183
|
+
|
|
184
|
+
$ docker exec hh-demo-blog mongorestore --archive=/srv/blog/dump/blog.archive --drop
|
|
185
|
+
$ docker exec hh-demo-blog mongosh --quiet --eval 'db.getSiblingDB("blog").posts.countDocuments()'
|
|
186
|
+
3
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Three documents, on a host that started with nothing.
|
|
190
|
+
|
|
191
|
+
## What is recovered, and what is not
|
|
192
|
+
|
|
193
|
+
| | |
|
|
194
|
+
| --- | --- |
|
|
195
|
+
| ✅ **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. |
|
|
196
|
+
| ⚠️ **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. |
|
|
197
|
+
| ⚠️ **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. |
|
|
198
|
+
| ❌ **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. |
|
|
199
|
+
| ❌ **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. |
|
|
200
|
+
| ❌ **Not recovered** | The UI you had installed, if it was not the stock one. An official UI is fetched again on the next `up`. |
|
|
201
|
+
|
|
202
|
+
## Re-running it
|
|
203
|
+
|
|
204
|
+
The script is the reproducible form of everything above:
|
|
205
|
+
|
|
206
|
+
```sh
|
|
207
|
+
docs/demo/blank-host-restore.sh
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
It creates two state directories, seeds a real MongoDB, dumps it, backs it up, restores onto the
|
|
211
|
+
blank second host, starts the entry there and asserts the documents came back. It exits non-zero if
|
|
212
|
+
they do not.
|
package/docs/UI_CREATION.md
CHANGED
|
@@ -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,194 @@
|
|
|
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 --all` (plans first, then `--confirm` applies)
|
|
9
|
+
# 3. host B — a *blank* home, nothing configured
|
|
10
|
+
# 4. restore into it: `home-hosted backup restore <name> --all --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
|
+
# The plan first: what the archive would capture, written nothing.
|
|
95
|
+
HHOSTED_HOME="$HOST_A" "${CLI[@]}" backup create --all
|
|
96
|
+
HHOSTED_HOME="$HOST_A" "${CLI[@]}" backup create --all --confirm
|
|
97
|
+
ARCHIVE="$(HHOSTED_HOME="$HOST_A" "${CLI[@]}" backup list --json | node -e '
|
|
98
|
+
let raw = ""
|
|
99
|
+
process.stdin.on("data", chunk => raw += chunk)
|
|
100
|
+
process.stdin.on("end", () => {
|
|
101
|
+
const view = JSON.parse(raw)
|
|
102
|
+
process.stdout.write(view.files[0].name)
|
|
103
|
+
})
|
|
104
|
+
')"
|
|
105
|
+
note "archive: $ARCHIVE"
|
|
106
|
+
|
|
107
|
+
# Host A is gone, which is the premise of the whole exercise. Its container has to go with it, or
|
|
108
|
+
# the port is still held when host B tries to start the restored entry.
|
|
109
|
+
docker rm -f "$MONGO" >/dev/null 2>&1 || true
|
|
110
|
+
note "stopped host A's container (host A is gone, after all)"
|
|
111
|
+
|
|
112
|
+
say "What is in the archive"
|
|
113
|
+
node -e '
|
|
114
|
+
const { execFileSync } = require("node:child_process")
|
|
115
|
+
const out = execFileSync("unzip", ["-Z1", process.argv[1]], { encoding: "utf8" })
|
|
116
|
+
for (const line of out.trim().split("\n")) console.log(" " + line)
|
|
117
|
+
' "$HOST_A/.hh/.backups/$ARCHIVE" 2>/dev/null || note "(unzip not installed; skipping the listing)"
|
|
118
|
+
|
|
119
|
+
# ---------------------------------------------------------------------------- host B
|
|
120
|
+
|
|
121
|
+
say "Host B: a blank machine, nothing configured"
|
|
122
|
+
|
|
123
|
+
mkdir -p "$HOST_B"
|
|
124
|
+
if [ -e "$HOST_B/.hh/workspaces.json" ]; then
|
|
125
|
+
note "unexpected: host B is not blank"; exit 1
|
|
126
|
+
fi
|
|
127
|
+
note "$HOST_B has no .hh at all"
|
|
128
|
+
|
|
129
|
+
HHOSTED_HOME="$HOST_B" "${CLI[@]}" up --port "$PANEL_B" --no-autostart >/dev/null
|
|
130
|
+
# A token to authorise the upload. The archive carries host A's `secrets.json`, so this one is
|
|
131
|
+
# replaced by the restore and a fresh one is minted afterwards.
|
|
132
|
+
SETUP_TOKEN="$(HHOSTED_HOME="$HOST_B" "${CLI[@]}" set-token --generate | grep -oE 'hh_[A-Za-z0-9_-]+' | head -1)"
|
|
133
|
+
note "panel on :$PANEL_B"
|
|
134
|
+
|
|
135
|
+
# The archive travels as a file, which is the whole point: one artifact to move.
|
|
136
|
+
cp "$HOST_A/.hh/.backups/$ARCHIVE" "$WORK/$ARCHIVE"
|
|
137
|
+
|
|
138
|
+
# The plan first, always: a restore writes over live data, so the default is to say what it would do.
|
|
139
|
+
say "Planning the restore (nothing is written yet)"
|
|
140
|
+
mkdir -p "$HOST_B/.hh/.backups"
|
|
141
|
+
cp "$WORK/$ARCHIVE" "$HOST_B/.hh/.backups/$ARCHIVE"
|
|
142
|
+
HHOSTED_HOME="$HOST_B" "${CLI[@]}" backup restore "$ARCHIVE" --all
|
|
143
|
+
rm -f "$HOST_B/.hh/.backups/$ARCHIVE"
|
|
144
|
+
curl -fsS -o /dev/null -X POST \
|
|
145
|
+
-H "Authorization: Bearer $SETUP_TOKEN" \
|
|
146
|
+
-F "file=@$WORK/$ARCHIVE" \
|
|
147
|
+
"http://127.0.0.1:$PANEL_B/api/backups/restore?confirm=true"
|
|
148
|
+
note "uploaded and restored onto the blank host"
|
|
149
|
+
|
|
150
|
+
# The archive carried host A's `global/secrets.json`, so host B now has host A's password hash and
|
|
151
|
+
# API token hash — the archive is the whole machine's identity, not just its entries. The README
|
|
152
|
+
# warns about exactly this. A real move should either accept that or rotate afterwards; this demo
|
|
153
|
+
# rotates, because a token that travelled in an archive is a token in a file.
|
|
154
|
+
TOKEN_B="$(HHOSTED_HOME="$HOST_B" "${CLI[@]}" set-token --generate | grep -oE 'hh_[A-Za-z0-9_-]+' | head -1)"
|
|
155
|
+
note "rotated host B's API token (the archive had brought host A's)"
|
|
156
|
+
|
|
157
|
+
say "What host B now has"
|
|
158
|
+
HHOSTED_HOME="$HOST_B" "${CLI[@]}" status
|
|
159
|
+
|
|
160
|
+
# ---------------------------------------------------------------------------- prove it serves
|
|
161
|
+
|
|
162
|
+
say "Starting the restored entry"
|
|
163
|
+
|
|
164
|
+
START_ANSWER="$(curl -sS -X POST -H "Authorization: Bearer $TOKEN_B" \
|
|
165
|
+
"http://127.0.0.1:$PANEL_B/api/servers/blog-db/start?workspace=default")"
|
|
166
|
+
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"
|
|
167
|
+
|
|
168
|
+
for _ in $(seq 1 60); do
|
|
169
|
+
docker exec "$APP" mongosh --quiet --eval 'db.runCommand({ping:1}).ok' >/dev/null 2>&1 && break
|
|
170
|
+
sleep 1
|
|
171
|
+
done
|
|
172
|
+
|
|
173
|
+
say "Reading the database on the restored host"
|
|
174
|
+
|
|
175
|
+
docker cp "$DATA/dump/blog.archive" "$APP:/tmp/blog.archive"
|
|
176
|
+
BEFORE="$(docker exec "$APP" mongosh --quiet --eval 'db.getSiblingDB("blog").posts.countDocuments()')"
|
|
177
|
+
note "documents in blog.posts before applying the dump: $BEFORE — the container is fresh, so it is empty"
|
|
178
|
+
|
|
179
|
+
# The dump is the data; restoring the *panel* brought back the entry and the dump beside it. Applying
|
|
180
|
+
# the dump is the database's own step, and this is it.
|
|
181
|
+
docker exec "$APP" mongorestore --archive=/tmp/blog.archive --quiet --drop
|
|
182
|
+
COUNT="$(docker exec "$APP" mongosh --quiet --eval 'db.getSiblingDB("blog").posts.countDocuments()')"
|
|
183
|
+
TITLES="$(docker exec "$APP" mongosh --quiet --eval 'db.getSiblingDB("blog").posts.find({}, {title:1, _id:0}).toArray().map(p => p.title).join(" | ")')"
|
|
184
|
+
|
|
185
|
+
say "Result"
|
|
186
|
+
note "blog.posts documents: $COUNT"
|
|
187
|
+
note "titles: $TITLES"
|
|
188
|
+
|
|
189
|
+
if [ "$COUNT" = "3" ]; then
|
|
190
|
+
printf '\n\033[32mrestored: the same 3 documents, on a host that started blank\033[0m\n'
|
|
191
|
+
else
|
|
192
|
+
printf '\n\033[31mFAILED: expected 3 documents, got %s\033[0m\n' "$COUNT"
|
|
193
|
+
exit 1
|
|
194
|
+
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
|
+
"version": "0.9.6",
|
|
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,28 +59,28 @@
|
|
|
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": {
|
|
70
72
|
"node": ">=24.0.0"
|
|
71
73
|
},
|
|
72
74
|
"scripts": {
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
75
|
+
"cli": "tsx src/cli.ts --home .dev-state",
|
|
76
|
+
"up": "pnpm run cli up",
|
|
77
|
+
"down": "pnpm run cli down",
|
|
78
|
+
"status": "pnpm run cli status",
|
|
79
|
+
"restart": "pnpm run cli restart",
|
|
80
|
+
"start": "pnpm run cli up --foreground",
|
|
78
81
|
"dev": "node scripts/dev.mjs",
|
|
79
82
|
"build": "pnpm run build:ui && pnpm run build:server",
|
|
80
83
|
"build:server": "vite build --config vite.server.config.ts",
|
|
81
|
-
"set-password": "tsx src/cli.ts set-password",
|
|
82
|
-
"set-token": "tsx src/cli.ts set-token",
|
|
83
|
-
"migrate": "tsx src/cli.ts migrate",
|
|
84
84
|
"lint": "eslint .",
|
|
85
85
|
"test:docs": "node scripts/check-doc-links.mjs",
|
|
86
86
|
"test": "vitest",
|
package/uis/stock/dist/ui.json
CHANGED