Automated backups using GitHub Actions
Backup your database on a regular basis.
You can use the Supabase CLI to backup your Postgres database. The steps involve running a series of commands to dump roles, schema, and data separately.
Inside your repository, create a new file inside the .github/workflows
folder called backup.yml
. Copy the following snippet inside the file, and the action will run whenever a new PR is created.
Never backup your data to a public repository.
Backup action
Periodic Backups Workflow
You can use the GitHub Action to run periodic backups of your database. In this example, the Action workflow is triggered by push
and pull_request
events on the main
branch, manually via workflow_dispatch
, and automatically at midnight every day due to the schedule
event with a cron
expression.
The workflow runs on the latest Ubuntu runner and requires write permissions to the repository's contents. It uses the Supabase CLI to dump the roles, schema, and data from your Supabase database, utilizing the SUPABASE_DB_URL
environment variable that is securely stored in the GitHub secrets.
After the backup is complete, it auto-commits the changes to the repository using the git-auto-commit-action
. This ensures that the latest backup is always available in your repository. The commit message for these automated commits is "Supabase backup".
This workflow provides an automated solution for maintaining regular backups of your Supabase database. It helps keep your data safe and enables easy restoration in case of any accidental data loss or corruption.
Never backup your data to a public repository.
More resources
- Backing up and migrating your project: Migrating and Upgrading