0
0
Supabasecloud~5 mins

Backup and disaster recovery in Supabase

Choose your learning style9 modes available
Introduction

Backup and disaster recovery help keep your data safe and restore it if something goes wrong.

You want to save copies of your database regularly to avoid data loss.
You need to recover your app quickly after accidental deletion or errors.
You want to protect your data from hardware failures or cyber attacks.
You want to meet rules that require data protection and recovery plans.
Syntax
Supabase
1. Enable automated backups in Supabase project settings.
2. Use Supabase CLI or API to create manual backups.
3. Restore backups via Supabase dashboard or CLI when needed.
Supabase automatically creates daily backups for your database.
You can download backups or restore them anytime from the dashboard.
Examples
This command saves a copy of your database to a file named backup.sql.
Supabase
# To create a manual backup using Supabase CLI
supabase db dump --file backup.sql
This command restores your database from the backup.sql file using psql. Ensure DATABASE_URL is set to your Supabase DB URL.
Supabase
# To restore a backup using psql CLI
psql $DATABASE_URL < backup.sql
This setting makes Supabase save your database daily without manual work.
Supabase
# Enable automated backups
Go to Supabase dashboard &gt; Project Settings &gt; Database &gt; Backups &gt; Turn on automated backups
Sample Program

This example shows how to enable backups, create a manual backup file, and restore it using Supabase CLI and psql.

Supabase
# Step 1: Enable automated backups in Supabase dashboard
# Step 2: Create a manual backup
supabase db dump --file my_backup.sql

# Step 3: Restore from backup if needed
psql $DATABASE_URL < my_backup.sql
OutputSuccess
Important Notes

Always test your backups by restoring them in a safe environment.

Keep backup files secure to prevent unauthorized access.

Automated backups help but manual backups give you control before big changes.

Summary

Backups save copies of your data to protect against loss.

Disaster recovery restores your data quickly after problems.

Supabase offers automated and manual backup options for safety.