backupdrill 2.9.2 → 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 +49 -5
- package/dist/auth-backup.d.ts +110 -0
- package/dist/auth-backup.js +383 -0
- package/dist/auth-drill.d.ts +69 -0
- package/dist/auth-drill.js +469 -0
- package/dist/auth-restore.d.ts +120 -0
- package/dist/auth-restore.js +633 -0
- package/dist/backup.d.ts +17 -0
- package/dist/backup.js +372 -19
- package/dist/config.d.ts +9 -0
- package/dist/config.js +17 -0
- package/dist/drill.d.ts +24 -3
- package/dist/drill.js +43 -3
- package/dist/dump-sql.d.ts +6 -0
- package/dist/dump-sql.js +31 -0
- package/dist/external-refs.d.ts +6 -1
- package/dist/external-refs.js +5 -0
- package/dist/index.js +67 -3
- package/dist/lib.d.ts +9 -3
- package/dist/lib.js +4 -2
- package/dist/manifest.d.ts +63 -0
- package/dist/manifest.js +78 -0
- package/dist/orphaned-foreign-keys.d.ts +13 -0
- package/dist/orphaned-foreign-keys.js +75 -25
- package/dist/pgbin.d.ts +7 -0
- package/dist/pgbin.js +24 -0
- package/dist/ping.js +1 -0
- package/dist/recovery-doc.d.ts +25 -0
- package/dist/recovery-doc.js +232 -53
- package/dist/restore-engine.d.ts +73 -1
- package/dist/restore-engine.js +155 -77
- package/dist/restore-record.d.ts +47 -0
- package/dist/restore-record.js +57 -0
- package/dist/restore.d.ts +64 -0
- package/dist/restore.js +348 -34
- package/dist/snapshot-store.d.ts +13 -0
- package/dist/snapshot-store.js +25 -0
- package/dist/snapshots.d.ts +2 -0
- package/dist/snapshots.js +10 -3
- package/package.json +1 -1
- package/plugin/README.md +1 -1
- package/plugin/skills/supabase-backup/SKILL.md +9 -7
- package/plugin/skills/supabase-backup/assets/scheduled-backup.yml +6 -1
- package/plugin/skills/supabase-backup/references/postgres-backup-basics.md +94 -0
|
@@ -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
|
+
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
|
|
|
@@ -69,7 +71,7 @@ Every backup reads the whole database, and every configured Storage file, out of
|
|
|
69
71
|
```sh
|
|
70
72
|
( set +x; unset DATABASE_URL $(env | sed -n 's/^\(BACKUPDRILL_[A-Za-z0-9_]*\)=.*/\1/p')
|
|
71
73
|
set -a; . ./.env.backupdrill 2>/dev/null || { echo ".env.backupdrill could not be loaded" >&2; exit 1; }; set +a
|
|
72
|
-
npx -y backupdrill@2.
|
|
74
|
+
npx -y backupdrill@2.10.0 estimate --plan pro )
|
|
73
75
|
```
|
|
74
76
|
|
|
75
77
|
Use `--plan free`, `pro` or `team` to match their Supabase plan, and read the projection back before suggesting a daily schedule. On a large database, suggest weekly.
|
|
@@ -80,12 +82,12 @@ Use `--plan free`, `pro` or `team` to match their Supabase plan, and read the pr
|
|
|
80
82
|
report="$(mktemp "${TMPDIR:-/tmp}/backupdrill-backup.XXXXXX")" || exit 1; echo "stdout → $report"
|
|
81
83
|
( set +x; unset DATABASE_URL $(env | sed -n 's/^\(BACKUPDRILL_[A-Za-z0-9_]*\)=.*/\1/p')
|
|
82
84
|
set -a; . ./.env.backupdrill 2>/dev/null || { echo ".env.backupdrill could not be loaded" >&2; exit 1; }; set +a
|
|
83
|
-
npx -y backupdrill@2.
|
|
85
|
+
npx -y backupdrill@2.10.0 backup ) > "$report"
|
|
84
86
|
```
|
|
85
87
|
|
|
86
88
|
- The progress lines on stderr show where everything went (`Dumping → s3://…`, `Manifest written → s3://…`) and end with `Backup complete — N tables + M Storage files`. stdout goes to the file named on the first line, a new one each run that only the user can read: one line of JSON with the whole manifest, which lists every table and Storage file, so read only the fields you need from it.
|
|
87
89
|
- Report the table count, the Storage file count (or that it was database only), and where the snapshot landed: `<prefix>/<project>/<timestamp>/` in their bucket, holding `dump.pgcustom`, `manifest.json`, `RECOVERY.md` and, with Storage keys set, `storage/`.
|
|
88
|
-
- By default only the `public` schema is dumped (add their own schemas with `--schema`), so Supabase-managed schemas such as `auth` and `storage` aren't in it. The dump has no grants; the manifest records what `anon`, `authenticated` and `service_role` were granted, and `restore` and `drill` set that back.
|
|
90
|
+
- By default only the `public` schema is dumped (add their own schemas with `--schema`), so Supabase-managed schemas such as `auth` and `storage` aren't in it. Since 2.10.0 the Auth users (`auth.users` and `auth.identities`) go into a second archive, `auth.dump`, when the database role can read them, unless they turned that off with `--no-auth` or `BACKUPDRILL_AUTH=off`. The dump has no grants; the manifest records what `anon`, `authenticated` and `service_role` were granted, and `restore` and `drill` set that back.
|
|
89
91
|
- The CLI never deletes anything in the bucket. Old snapshots are cleaned up by the bucket's own lifecycle rules, if the user sets any.
|
|
90
92
|
|
|
91
93
|
## Prove the backup restores (drill)
|
|
@@ -93,7 +95,7 @@ report="$(mktemp "${TMPDIR:-/tmp}/backupdrill-backup.XXXXXX")" || exit 1; echo "
|
|
|
93
95
|
```sh
|
|
94
96
|
( set +x; unset DATABASE_URL $(env | sed -n 's/^\(BACKUPDRILL_[A-Za-z0-9_]*\)=.*/\1/p')
|
|
95
97
|
set -a; . ./.env.backupdrill 2>/dev/null || { echo ".env.backupdrill could not be loaded" >&2; exit 1; }; set +a
|
|
96
|
-
npx -y backupdrill@2.
|
|
98
|
+
npx -y backupdrill@2.10.0 drill )
|
|
97
99
|
```
|
|
98
100
|
|
|
99
101
|
- It reads the latest snapshot from the bucket, restores it into a throwaway Postgres container, runs its checks and removes the container. It doesn't connect to the Supabase project. The first run pulls a Postgres image from Docker Hub.
|
|
@@ -112,12 +114,12 @@ A restore writes data, so go step by step and let the user drive.
|
|
|
112
114
|
```sh
|
|
113
115
|
( set +x; unset DATABASE_URL $(env | sed -n 's/^\(BACKUPDRILL_[A-Za-z0-9_]*\)=.*/\1/p')
|
|
114
116
|
set -a; . ./.env.backupdrill 2>/dev/null || { echo ".env.backupdrill could not be loaded" >&2; exit 1; }; set +a
|
|
115
|
-
npx -y backupdrill@2.
|
|
117
|
+
npx -y backupdrill@2.10.0 restore --database --target-supabase-url https://<target-ref>.supabase.co --dry-run )
|
|
116
118
|
```
|
|
117
119
|
|
|
118
120
|
Leave out `--target-supabase-url` when the snapshot is database only. To write Storage files to a local folder instead of the new project, use `--storage-dir ./recovered`.
|
|
119
121
|
4. Show the dry-run result. It starts with `Dry run for snapshot <timestamp>`; note that timestamp. Run the real restore only after the user asks for it and gives you the target ref. Then replace `--dry-run` with `--snapshot <timestamp> --confirm-target <target-ref>`, using the timestamp from the dry run and exactly the ref they gave, so a backup that lands in between can't change what gets restored. Send stdout to a new `mktemp` file the same way as `backup` (with `backupdrill-restore.XXXXXX` as the name): the JSON result can be long. If the user wants an older snapshot, pass `--snapshot` to both runs.
|
|
120
|
-
5. Tell them what a restore doesn't bring back: Auth
|
|
122
|
+
5. Tell them what a restore doesn't bring back: Auth sessions and MFA factors, Auth settings (sign-in providers, SMTP, redirect URLs), secret values and Edge Functions. A snapshot that has Auth users (its manifest says so under `auth`) restores them with the database in one transaction; everyone signs in again afterwards. Snapshots without them, including every snapshot taken before 2.10.0, have no Auth users to restore. They need to set those up again. The `API grants` check line says what access `anon`, `authenticated` and `service_role` got; for a snapshot taken before 2.9.0 it is Supabase's old default access in `public`, so they should revoke it on anything they kept private. The snapshot's `RECOVERY.md` has a "Not covered" section on this.
|
|
121
123
|
6. Once they're done, suggest they delete the two `TARGET` lines from `.env.backupdrill`.
|
|
122
124
|
|
|
123
125
|
## Run it on a schedule
|
|
@@ -26,6 +26,10 @@
|
|
|
26
26
|
# BACKUPDRILL_SCHEMAS Comma-separated schemas to dump, e.g. public,audit
|
|
27
27
|
# (default: public). Use the same value as your
|
|
28
28
|
# local runs, or scheduled backups miss schemas.
|
|
29
|
+
# BACKUPDRILL_AUTH Supabase Auth users (auth.users + auth.identities)
|
|
30
|
+
# are backed up when the database role can read
|
|
31
|
+
# them. "off" leaves them out; "on" makes a backup
|
|
32
|
+
# that can't include them exit with code 3.
|
|
29
33
|
# BACKUPDRILL_S3_PREFIX Key prefix in the bucket (default: backupdrill).
|
|
30
34
|
# Keep it the same as local runs so drills and
|
|
31
35
|
# restores find these snapshots.
|
|
@@ -95,7 +99,7 @@ jobs:
|
|
|
95
99
|
|
|
96
100
|
- name: Run backupdrill
|
|
97
101
|
# Pinned so every run uses the same CLI. Raise it on purpose when you upgrade.
|
|
98
|
-
run: npx -y backupdrill@2.
|
|
102
|
+
run: npx -y backupdrill@2.10.0 backup
|
|
99
103
|
env:
|
|
100
104
|
# --- required ---
|
|
101
105
|
BACKUPDRILL_DATABASE_URL: ${{ secrets.BACKUPDRILL_DATABASE_URL }}
|
|
@@ -107,6 +111,7 @@ jobs:
|
|
|
107
111
|
BACKUPDRILL_S3_REGION: ${{ secrets.BACKUPDRILL_S3_REGION }}
|
|
108
112
|
BACKUPDRILL_PROJECT_NAME: ${{ secrets.BACKUPDRILL_PROJECT_NAME }}
|
|
109
113
|
BACKUPDRILL_SCHEMAS: ${{ secrets.BACKUPDRILL_SCHEMAS }}
|
|
114
|
+
BACKUPDRILL_AUTH: ${{ secrets.BACKUPDRILL_AUTH }}
|
|
110
115
|
BACKUPDRILL_S3_PREFIX: ${{ secrets.BACKUPDRILL_S3_PREFIX }}
|
|
111
116
|
BACKUPDRILL_S3_FORCE_PATH_STYLE: ${{ secrets.BACKUPDRILL_S3_FORCE_PATH_STYLE }}
|
|
112
117
|
# --- optional: also back up Supabase Storage files (set all four) ---
|
|
@@ -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).
|