backupdrill 2.10.0 → 2.10.1
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/README.md
CHANGED
|
@@ -336,6 +336,32 @@ Prefer a plain workflow file? [`examples/scheduled-backup.yml`](examples/schedul
|
|
|
336
336
|
|
|
337
337
|
Before switching to a **daily** schedule, read the egress-cost section above — every run is egress on your Supabase bill.
|
|
338
338
|
|
|
339
|
+
## Docker / scheduled backups on your own server
|
|
340
|
+
|
|
341
|
+
If you'd rather run backups on a machine you already have (a home server, a NAS, Unraid, any Docker host), use the image at `ghcr.io/backupdrill/backupdrill`. The image includes the CLI and `pg_dump` 17. It contains no credentials; configure it with the `BACKUPDRILL_*` environment variables listed above.
|
|
342
|
+
|
|
343
|
+
Set `BACKUPDRILL_CRON` and the container stays up and runs `backupdrill backup` on that schedule. The time zone comes from `TZ` (UTC if unset). If a scheduled backup is still running when the next one is due, the scheduler skips that run. A backup you start yourself with `docker exec` isn't covered by this and can overlap with a scheduled one.
|
|
344
|
+
|
|
345
|
+
```bash
|
|
346
|
+
docker run -d --name backupdrill --restart unless-stopped \
|
|
347
|
+
-e BACKUPDRILL_CRON="0 3 * * 0" \
|
|
348
|
+
-e TZ="Europe/Berlin" \
|
|
349
|
+
-e BACKUPDRILL_DATABASE_URL="postgresql://postgres.<ref>:<pw>@<pooler-host>:5432/postgres" \
|
|
350
|
+
-e BACKUPDRILL_PROJECT_NAME="my-app" \
|
|
351
|
+
-e BACKUPDRILL_S3_ENDPOINT="https://<account>.r2.cloudflarestorage.com" \
|
|
352
|
+
-e BACKUPDRILL_S3_BUCKET="my-backups" \
|
|
353
|
+
-e BACKUPDRILL_S3_ACCESS_KEY_ID="…" \
|
|
354
|
+
-e BACKUPDRILL_S3_SECRET_ACCESS_KEY="…" \
|
|
355
|
+
-e BACKUPDRILL_PING_URL="https://hc-ping.com/<uuid>" \
|
|
356
|
+
ghcr.io/backupdrill/backupdrill:latest
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
- Without `BACKUPDRILL_CRON` the container runs one backup and exits with the CLI's exit code, which suits a host cron job or a scheduler you already use.
|
|
360
|
+
- Arguments go straight to the CLI: `docker run --rm -e … ghcr.io/backupdrill/backupdrill estimate` or `… --help`. To start a backup now in a running scheduled container: `docker exec backupdrill backupdrill backup`.
|
|
361
|
+
- `BACKUPDRILL_CRON` takes a standard 5-field expression or a shortcut such as `@daily`. Anything else stops the container at start (exit code 64) instead of leaving it idle.
|
|
362
|
+
- `drill` needs Docker to start its throwaway Postgres, and the image doesn't get access to your Docker daemon, so run drills where Docker is available (your machine, or the GitHub Action with `drill: "true"`).
|
|
363
|
+
- Tags: `latest`, the CLI version (e.g. `2.10.1`), and `sha-<commit>`. Images are built for amd64 and arm64.
|
|
364
|
+
|
|
339
365
|
## Alerts with Healthchecks.io
|
|
340
366
|
|
|
341
367
|
A scheduled backup can fail quietly, or not run at all: a cron entry that never fires, a runner that dies, a workflow GitHub disabled. `backup` and `drill` can report every run to a [Healthchecks.io](https://healthchecks.io) check (a self-hosted Healthchecks works the same), and Healthchecks alerts you when a run fails or a success ping doesn't arrive on time.
|
package/dist/drill.js
CHANGED
|
@@ -172,6 +172,10 @@ async function startEphemeralPostgres(image, major, resourceName) {
|
|
|
172
172
|
await ensureImage(image);
|
|
173
173
|
// 名字先定好:Ctrl+C 可能落在 docker run 还没返回 ID 的时候,按名字才删得掉
|
|
174
174
|
const name = resourceName ?? `backupdrill-drill-${randomBytes(6).toString("hex")}`;
|
|
175
|
+
// 沙箱里是恢复出来的生产数据。端口只绑 127.0.0.1,但同机的其他系统账号照样连得上,
|
|
176
|
+
// 固定密码等于没设:每个沙箱一个随机密码。只写 "-e POSTGRES_PASSWORD" 不带值,
|
|
177
|
+
// docker 从它自己的环境变量取值,密码就不进 argv(ps 看得到 argv)
|
|
178
|
+
const password = randomBytes(16).toString("hex");
|
|
175
179
|
throwIfInterrupted();
|
|
176
180
|
const started = execFileAsync("docker", [
|
|
177
181
|
"run",
|
|
@@ -181,7 +185,7 @@ async function startEphemeralPostgres(image, major, resourceName) {
|
|
|
181
185
|
name,
|
|
182
186
|
...(resourceName ? ["--mount", `type=volume,source=${resourceName},target=${dataVolumeTarget}`] : []),
|
|
183
187
|
"-e",
|
|
184
|
-
"POSTGRES_PASSWORD
|
|
188
|
+
"POSTGRES_PASSWORD",
|
|
185
189
|
"-e",
|
|
186
190
|
"POSTGRES_DB=postgres",
|
|
187
191
|
"-p",
|
|
@@ -190,7 +194,7 @@ async function startEphemeralPostgres(image, major, resourceName) {
|
|
|
190
194
|
image,
|
|
191
195
|
"postgres",
|
|
192
196
|
...tuning.settings.flatMap((kv) => ["-c", kv]),
|
|
193
|
-
]);
|
|
197
|
+
], { env: { ...process.env, POSTGRES_PASSWORD: password } });
|
|
194
198
|
// 删容器只有一份:正常收尾(drillDump 的 finally)和中断收尾(interrupt.ts)等的是同一个 promise。
|
|
195
199
|
// 两边各发一次 docker rm 会撞上 "removal already in progress",后到的那个报删除失败,
|
|
196
200
|
// 进程又在真正删完之前就退出了(信号测试抓到的竞争)。
|
|
@@ -259,7 +263,7 @@ async function startEphemeralPostgres(image, major, resourceName) {
|
|
|
259
263
|
]);
|
|
260
264
|
// 形如 "127.0.0.1:54321"
|
|
261
265
|
const port = portOut.stdout.trim().split(":").pop().trim();
|
|
262
|
-
const connString = `postgresql://postgres
|
|
266
|
+
const connString = `postgresql://postgres:${password}@127.0.0.1:${port}/postgres`;
|
|
263
267
|
// 等就绪(容器内 pg_isready),最多 ~30s。
|
|
264
268
|
// 必须 -h 127.0.0.1 强制走 TCP:官方镜像 initdb 阶段先起一个只听 unix socket 的临时
|
|
265
269
|
// 服务跑初始化,默认(socket)检查在该阶段就通过,pg_restore 随后连 TCP 正撞上
|
package/package.json
CHANGED
|
@@ -7,7 +7,9 @@ description: Use when the user wants to back up a Supabase project to their own
|
|
|
7
7
|
|
|
8
8
|
backupdrill is an open-source (MIT) command-line tool. `backup` dumps the project's Postgres database with `pg_dump`, copies Storage files too once their S3 keys are set, and writes everything to a bucket the user owns, with a checksummed `manifest.json` and a `RECOVERY.md` in every snapshot. `drill` restores a snapshot into a throwaway Postgres in Docker and checks that it came back. The CLI runs on the user's machine. It talks to their Supabase project, their bucket and the local Docker daemon, and sends nothing to BackupDrill.
|
|
9
9
|
|
|
10
|
-
Always run it as `npx -y backupdrill@2.10.0 <command>`, so every run uses the same version.
|
|
10
|
+
Always run it as `npx -y backupdrill@2.10.0 <command>`, so every run uses the same version. Every command and option is documented at [backupdrill.com/docs/cli](https://backupdrill.com/docs/cli); check there before using an option this skill doesn't mention.
|
|
11
|
+
|
|
12
|
+
If the user asks what Supabase already backs up on their plan, wants a plain `pg_dump` backup without the CLI, or wants to test a restore by hand, read [references/postgres-backup-basics.md](references/postgres-backup-basics.md).
|
|
11
13
|
|
|
12
14
|
You need a shell on the user's machine for this. If you don't have one, walk the user through the same commands instead of running them.
|
|
13
15
|
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Supabase backups without the CLI: pg_dump, pg_restore and the Free plan
|
|
2
|
+
|
|
3
|
+
Read this when the user asks what Supabase already backs up for them, wants a plain `pg_dump` backup instead of the CLI, or wants to test a restore by hand. The commands here are what `backupdrill backup` and `backupdrill drill` automate.
|
|
4
|
+
|
|
5
|
+
## What Supabase keeps for you
|
|
6
|
+
|
|
7
|
+
- **Free plan:** no access to automatic backups. Supabase's docs tell Free projects to export their data themselves (`supabase db dump`) and keep off-site copies. Free projects are paused after a week of inactivity; the pause snapshot lets the user restore the paused project from the dashboard for up to a year.
|
|
8
|
+
- **Pro and Team:** daily backups, kept 7 days on Pro and 14 on Team, restorable from the dashboard. On the physical backup process that current projects use they can't be downloaded. Point-in-time recovery is a paid add-on: about $100/month per project for 7 days of history.
|
|
9
|
+
- **Storage files are not in any database backup.** A database restore brings back the `storage.objects` rows, which only point at files. The files themselves need a separate copy (the CLI copies them once the Storage S3 keys are set).
|
|
10
|
+
|
|
11
|
+
Every backup taken from outside the project counts as egress on the user's Supabase bill. Free includes 5 GB a month, shared with whatever the app already serves. Run `backupdrill estimate --plan free` for an upper-bound estimate of the project's backup egress. As a rough guide, if each run transfers 500 MB (the Free database limit), weekly backups use about 2 GB a month and daily ones about 15 GB, three times the allowance.
|
|
12
|
+
|
|
13
|
+
## Use the Session pooler connection string
|
|
14
|
+
|
|
15
|
+
In the dashboard, **Connect** → **Session pooler**: port 5432, user `postgres.<project-ref>`. Copy the host from there as it is; it can't be worked out from the region. Without the IPv4 add-on, the direct connection needs IPv6, so on an IPv4-only home or CI network it won't connect. Don't use port 6543, the transaction pooler: `pg_dump` needs a session.
|
|
16
|
+
|
|
17
|
+
## Match client and server versions
|
|
18
|
+
|
|
19
|
+
- `pg_dump`'s major version must be at least the server's. Supabase runs Postgres 15 to 17, so a version 17 client covers all of them. Check with `pg_dump --version`.
|
|
20
|
+
- `pg_restore` must be at least as new as the `pg_dump` that wrote the archive. Archives from `pg_dump` 18 can contain SQL that Postgres 17 rejects, so stay on 17 unless the project runs something newer.
|
|
21
|
+
|
|
22
|
+
## A plain backup
|
|
23
|
+
|
|
24
|
+
Keep the password off the command line, where other users on the machine can see it in the process list. Ask the user to add one line to `~/.pgpass` themselves and make the file private (`chmod 600 ~/.pgpass`); `pg_dump`, `pg_restore` and `psql` read it, so the connection string carries no password:
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
<pooler-host>:5432:postgres:postgres.<project-ref>:<password>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
In that file a `:` or `\` inside the password has to be written as `\:` or `\\`.
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
export DB_URL="postgresql://postgres.<project-ref>@<pooler-host>:5432/postgres?sslmode=require"
|
|
34
|
+
export BACKUP_FILE="backup-$(date +%Y%m%dT%H%M%S).dump"
|
|
35
|
+
|
|
36
|
+
# umask 077 in a subshell: the dump is production data, so only the user can read it
|
|
37
|
+
( umask 077 && pg_dump "$DB_URL" --format=custom --schema=public --file="$BACKUP_FILE" ) \
|
|
38
|
+
&& pg_restore --list "$BACKUP_FILE" > /dev/null && echo "archive is readable"
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
- `sslmode=require` encrypts the connection. To also check the server's certificate, download the CA certificate from the project's database settings (SSL Configuration) and use `sslmode=verify-full&sslrootcert=<path to the certificate>`.
|
|
42
|
+
- `--format=custom` writes an archive that only `pg_restore` reads; it allows selective and parallel restores. A plain-text dump goes through `psql` instead.
|
|
43
|
+
- `--schema=public` leaves out Supabase-managed schemas, including `auth`, so Auth users aren't in this file. Add `--schema=<name>` for each of the app's own schemas.
|
|
44
|
+
- With `--schema`, `pg_dump` also leaves out large objects (the `lo_*` / `oid` kind, not Storage files). If the app uses them, add `--large-objects`.
|
|
45
|
+
- Never ask for the password in the chat. With the CLI, it lives in `.env.backupdrill` as `SKILL.md` describes.
|
|
46
|
+
|
|
47
|
+
## Test the restore by hand
|
|
48
|
+
|
|
49
|
+
A dump that has never been restored is a guess. Restore it into a throwaway Postgres and look at the data. The container will hold a copy of production data, and every account on the machine can reach a port on `127.0.0.1`, so give it a new random password. Start the container and wait until it accepts connections:
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
TEST_PW="$(openssl rand -hex 16)"
|
|
53
|
+
# docker run can print an ID and still fail (port taken), so only a zero exit counts.
|
|
54
|
+
# -e with no value makes docker read the password from its own environment, not from its arguments.
|
|
55
|
+
cid="$(POSTGRES_PASSWORD="$TEST_PW" docker run -d --rm -e POSTGRES_PASSWORD -p 127.0.0.1:55432:5432 postgres:17-alpine)" || cid=""
|
|
56
|
+
[ -n "$cid" ] \
|
|
57
|
+
&& for i in $(seq 60); do docker exec "$cid" pg_isready -q -h 127.0.0.1 -U postgres && break; sleep 1; done \
|
|
58
|
+
&& docker exec "$cid" pg_isready -h 127.0.0.1 -U postgres
|
|
59
|
+
echo "container: ${cid:-not started}"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
If it prints `container: not started` (port 55432 already taken, for example) or the last `pg_isready` says `no response`, stop and fix that first. Then restore and check:
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
export TEST_DB="postgresql://postgres@127.0.0.1:55432/postgres"
|
|
66
|
+
# PGPASSWORD goes on each command, not exported: exported, it would also replace
|
|
67
|
+
# ~/.pgpass for the production connection in this shell.
|
|
68
|
+
|
|
69
|
+
# The dump creates schema public itself, so drop the empty one first. Then add stand-ins
|
|
70
|
+
# for what a Supabase project provides, so policies that mention them restore.
|
|
71
|
+
# --no-privileges skips GRANT and REVOKE: this test checks the data, not who can read it.
|
|
72
|
+
PGPASSWORD="$TEST_PW" psql "$TEST_DB" --set ON_ERROR_STOP=1 -c "
|
|
73
|
+
drop schema public;
|
|
74
|
+
create role anon; create role authenticated; create role service_role;
|
|
75
|
+
create schema auth;
|
|
76
|
+
create function auth.uid() returns uuid language sql stable as 'select null::uuid';
|
|
77
|
+
create function auth.role() returns text language sql stable as 'select null::text';
|
|
78
|
+
create function auth.email() returns text language sql stable as 'select null::text';
|
|
79
|
+
create function auth.jwt() returns jsonb language sql stable as 'select null::jsonb';" \
|
|
80
|
+
&& PGPASSWORD="$TEST_PW" pg_restore --no-owner --no-privileges --dbname "$TEST_DB" "$BACKUP_FILE"
|
|
81
|
+
|
|
82
|
+
PGPASSWORD="$TEST_PW" psql "$TEST_DB" -c "select count(*) from pg_tables where schemaname = 'public';"
|
|
83
|
+
PGPASSWORD="$TEST_PW" psql "$TEST_DB" -c "select count(*) from public.<a table that must never be empty>;"
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
When you're done, remove only the container you started: `docker rm -f "$cid"`.
|
|
87
|
+
|
|
88
|
+
- `pg_restore` keeps going after an error and prints how many it ignored at the end. Read every error. The one expected failure is a foreign key to `auth.users` (a `profiles` table usually has one): this dump has no Auth users, so the constraint can't be created here. Anything else is a failed test.
|
|
89
|
+
- Compare the table count and a few row counts with the same queries on production. For a table that only grows, `max(created_at)` shows how recent the backup is.
|
|
90
|
+
- If the schema uses extensions, the restore fails on the first object that needs one the container doesn't have. Install the missing extension in the container first. The CLI's drill tries to install the extensions listed in the snapshot's manifest and reports any its container can't install; a restore can still fail on those.
|
|
91
|
+
|
|
92
|
+
## What the CLI adds
|
|
93
|
+
|
|
94
|
+
`backupdrill backup` runs the same `pg_dump`, copies Storage files, and writes a checksummed `manifest.json` and a `RECOVERY.md` next to the dump in the user's bucket. `backupdrill drill` does the restore test above against the latest snapshot in that bucket and reports each check. The full command reference is at [backupdrill.com/docs/cli](https://backupdrill.com/docs/cli).
|