Skip to content
ReviveDB
Blog

Automatic Supabase backups with GitHub Actions

By ReviveDB

GitHub Actions can run the Supabase CLI on a schedule without keeping your own machine online. The job still uses Supabase egress and GitHub Actions or artifact allowances. Supabase has an official example workflow. It works, but it commits every dump into the repository, and that is the part we would change.

Why not commit the dump

A dump in git stays in the history, including every user who later asks to be deleted. Removing someone means rewriting history on every clone. The repository also grows by a full copy of your data each day. Keep the files as build artifacts or in a bucket, where they expire.

A workflow that keeps dumps out of git

name: Supabase backup

on:
schedule:
- cron: '17 3 * * *'
workflow_dispatch:

jobs:
backup:
runs-on: ubuntu-latest
steps:
- uses: supabase/setup-cli@v1
with:
version: 2.118.0
- name: Dump roles, schema and data
env:
SUPABASE_DB_URL: ${{ secrets.SUPABASE_DB_URL }}
run: |
supabase db dump --db-url "$SUPABASE_DB_URL" -f roles.sql --role-only
supabase db dump --db-url "$SUPABASE_DB_URL" -f schema.sql
supabase db dump --db-url "$SUPABASE_DB_URL" -f data.sql --data-only --use-copy
- uses: actions/upload-artifact@v7
with:
name: supabase-backup-${{ github.run_id }}
path: '*.sql'
retention-days: 14

This workflow pins CLI v2, where --db-url selects the source database. For CLI v3, use --remote="$SUPABASE_DB_URL" instead. The dump flags are explained in our Supabase CLI backup guide.

Things that will bite you

  • Use the session pooler connection string from the Connect dialog. The direct database host only has an IPv6 address unless you pay for the IPv4 add-on, and GitHub's hosted runners cannot reach it.
  • Pin the CLI version. With version: latest, a new CLI release can change the dump output on a random night. Update the pin when you have tested a new version.
  • Scheduled runs can start late when GitHub is busy, and GitHub sends failure emails only to the person who last changed the schedule. Make sure that person reads them.
  • Artifacts are visible to everyone with read access to the repository. If that is more people than should see your production data, upload to a private bucket instead.
  • Every run downloads your whole database from Supabase, and that counts as egress.

What the dump does not contain

Part of the projectIn the dump?
Tables, rows, RLS policies, functionsYes
Auth usersYes, they are rows in the auth schema
Storage filesNo, only their metadata rows
Edge FunctionsNo
Secrets and API keysNo

For the gaps, see do Supabase backups include Storage files and how to back up Edge Functions.

Test that it restores

A green run proves the dump finished. It does not prove that it restores. A plain Postgres container is the wrong test target: it lacks the roles and extensions Supabase uses, so the restore fails on things that are fine in production. Running supabase start in a second job gives you a local Supabase stack to load the three files into. How to test a Supabase backup covers what to compare once it has loaded.

When to stop maintaining it

For a side project this workflow is enough. Once losing Storage files or a week of silent failures would hurt, it is a lot of pieces to keep working. ReviveDB backs up the database and Auth, Storage files, Edge Function code and deploy metadata, along with Storage bucket settings, and restore-tests every database backup. The free plan covers one project.