Guide

Supabase backups with GitHub Actions to S3 or R2

A copy-paste GitHub Actions workflow that dumps a Supabase database every night with the right pg_dump, checks it restores, and uploads it to Amazon S3 or Cloudflare R2.

By Sascha Heyer · Last updated December 4, 2026

GitHub Actions is the cheapest scheduler most teams already have. This guide builds a nightly Supabase backup on it, step by step: the right pg_dump version, a read-only database role, an upload to S3 or R2, retention, and an alert when it fails. Every command below runs on the standard ubuntu-latest runner.

1. A read-only role for the job

Do not give CI the postgres password. Create a role that can read everything and change nothing, in the Supabase SQL editor:

create role liferaft_backup with login password 'a-long-random-password' bypassrls;
grant pg_read_all_data to liferaft_backup;

Build the Session pooler connection string with that role (liferaft_backup.<project-ref> as the user) and save it as the repository secret SUPABASE_DB_URL. Use port 5432; the transaction pooler on 6543 does not work for pg_dump.

2. A bucket with a lifecycle rule

Create a private bucket on Amazon S3 or Cloudflare R2 and give it a lifecycle rule that deletes objects after, say, 30 days, so old dumps do not pile up. Create an access key that can only write to that bucket and save it as BACKUP_ACCESS_KEY_ID and BACKUP_SECRET_ACCESS_KEY. For R2, also save the endpoint https://<account-id>.r2.cloudflarestorage.com as BACKUP_ENDPOINT; for S3, leave that secret out.

3. The workflow

Save this as .github/workflows/supabase-backup.yml. It uses the free liferaft CLI to dump with exact row counts and then restore the dump into a throwaway Postgres on the runner, so the job fails if the copy does not come back complete:

name: supabase-backup
on:
  schedule: [{ cron: '17 3 * * *' }]   # every night at 03:17 UTC
  workflow_dispatch: {}

jobs:
  backup:
    runs-on: ubuntu-latest
    timeout-minutes: 60
    env:
      AWS_ACCESS_KEY_ID: ${{ secrets.BACKUP_ACCESS_KEY_ID }}
      AWS_SECRET_ACCESS_KEY: ${{ secrets.BACKUP_SECRET_ACCESS_KEY }}
      AWS_DEFAULT_REGION: auto                       # R2; use your bucket's region for S3
      AWS_REQUEST_CHECKSUM_CALCULATION: when_required   # needed by R2 with recent AWS CLIs
      AWS_RESPONSE_CHECKSUM_VALIDATION: when_required
    steps:
      - name: Postgres 17 binaries (pg_dump, psql, initdb)
        run: |
          sudo apt-get install -y postgresql-common
          sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y
          sudo apt-get install -y postgresql-17
      - uses: actions/setup-node@v4
        with: { node-version: 22 }
      - name: Dump with row counts
        env:
          LIFERAFT_DB: ${{ secrets.SUPABASE_DB_URL }}
        run: npx -y github:SaschaHeyer/liferaft-cli dump -o backup.sql.gz
      - name: Restore drill (fails the job if any table is short)
        run: npx -y github:SaschaHeyer/liferaft-cli drill backup.sql.gz
      - name: Upload
        run: |
          KEY="supabase/$(date -u +%F)"
          EP=${{ secrets.BACKUP_ENDPOINT && format('--endpoint-url {0}', secrets.BACKUP_ENDPOINT) || '' }}
          aws s3 cp backup.sql.gz "s3://my-supabase-backups/$KEY.sql.gz" $EP
          aws s3 cp backup.manifest.json "s3://my-supabase-backups/$KEY.manifest.json" $EP

The manifest next to each dump holds the Postgres version, every table’s row count and the file’s sha256 checksum, which is what you compare against when you restore it later. If you prefer plain pg_dump, replace the two liferaft steps with the command from the backup guide, called as /usr/lib/postgresql/17/bin/pg_dump; the runner’s default client is older than Supabase’s Postgres 17 and stops with “server version mismatch”.

4. Know when it fails

GitHub emails the person who last changed the workflow when a scheduled run fails, which is easy to miss. Add an explicit alert as the last step, for example to a Slack or Discord webhook:

      - name: Alert on failure
        if: failure()
        run: curl -fsS -X POST -H 'Content-Type: application/json' -d '{"text":"Supabase backup failed: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"}' "${{ secrets.ALERT_WEBHOOK }}"

5. Back up Storage files in the same job

The database dump does not contain uploaded files. Add a step that syncs each bucket through Supabase’s S3 endpoint to your backup bucket; the Storage backup guide has the loop and the key setup.

Limits of the do-it-yourself job

  • GitHub’s docs say scheduled workflows can be delayed when Actions is busy, and in public repositories they are switched off after 60 days without activity in the repository.
  • Runner time on private repositories counts against your Actions minutes.
  • Each run reads the whole database out of Supabase, which counts as egress on your Supabase bill (5 GB a month on Free, 250 GB on Pro). On Free, run it weekly; the egress guide has the sums.
  • Keep the workflow in a private repository: logs and artifacts of a backup job are not something to publish.
  • You own the upkeep: Postgres upgrades, expired keys, and noticing the day the alert webhook itself stopped working.

If you would rather not maintain it, Liferaft runs the same engine for you every night, stores the copies outside Supabase (no bucket to create), restores the newest one every week and emails the table-by-table report. Free for one project; Solo is $9 a month for 5.

Rather not run this yourself? Liferaft runs the dump every night through a read-only role, stores the copy outside Supabase, and restores it every week to count every row. Free for one Supabase project; Solo is $9 a month for five. Back up my Supabase project free

Frequently asked questions

Is it OK to store Supabase backups in the GitHub repository?

No. A dump contains your users’ emails and password hashes. Upload it to a private bucket and let the workflow only hold credentials in GitHub secrets.

Why does the workflow install pg_dump 17?

ubuntu-latest ships an older Postgres client, and pg_dump refuses to dump a newer server (“server version mismatch”). A newer pg_dump dumps older servers fine, so pg_dump 17 covers Supabase projects on Postgres 15 and 17.

Are scheduled GitHub Actions reliable for backups?

Mostly. GitHub documents that scheduled workflows can be delayed during busy periods, and they are disabled automatically in public repositories after 60 days without activity. Add a failure alert and check the bucket now and then.

More guides

Compare Supabase backup tools