Demo, all content is generated
Question

How do I make my own backup of my Supabase database?

Solved · 1024 views · asked by wairimu · edited

I have customers now (a small booking tool for 3 hair salons) and I'm scared of losing data. I see a backups page in the dashboard but I'm not sure what's in it or if I can download it. I'd like to have a copy on my own computer every week. What's the simplest way that I won't mess up?

What I’ve tried

Tried the export CSV button per table but that's 9 tables and it doesn't include my functions and policies.

Comment

3 answers

Marked as helpful by the asker
postgres_pete · edited

Use the CLI, it wraps pg_dump with the right flags for Supabase:

supabase db dump --db-url "$DB_URL" -f roles.sql --role-only
supabase db dump --db-url "$DB_URL" -f schema.sql
supabase db dump --db-url "$DB_URL" -f data.sql --use-copy --data-only

That gives you roles, schema (tables, functions, policies) and data. Use the session pooler URL if your network doesn't do IPv6.

Three things people forget:

  1. Storage files are not in the database dump. Only the metadata. Photos need a separate copy.
  2. auth.users is in the data dump. Treat the files as sensitive, don't leave them in Downloads.
  3. A backup you never restored is a hope, not a backup. Restore it once into a local Supabase (supabase start, then psql the files in) and click around.

Once you pay for Pro you also get daily backups in the dashboard, but keep your own copy anyway.

Comment
Did it and restored locally, it works! Put the 3 commands in a script with the date in the file names. wairimu · edited
"A backup you never restored is a hope" is going on a sticky note. ingrid_h · edited
chidi_eze · edited

For the weekly part: a GitHub Action on a schedule that runs these and uploads to a private bucket somewhere else (Backblaze, R2). Encrypt it first with age or gpg, it contains your customers' data.

Comment
Encryption part is a bit above my level but I will try, thanks wairimu · edited
kofi_mensah · edited

Once you're on Pro, look at the point-in-time recovery add-on too. Daily backups mean you can lose up to a day of bookings; PITR gets that down to minutes. For 3 salons, maybe later, but good to know it exists.

Comment