Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

chore: add backup section to project migration guide (#12855)

Han Qiaoc484fc8412fc
diff --git a/apps/docs/pages/guides/platform/migrating-and-upgrading-projects.mdx b/apps/docs/pages/guides/platform/migrating-and-upgrading-projects.mdx
index 9b035e1264b..0586ea2c09c 100644
--- a/apps/docs/pages/guides/platform/migrating-and-upgrading-projects.mdx
+++ b/apps/docs/pages/guides/platform/migrating-and-upgrading-projects.mdx
@@ -21,42 +21,41 @@ When you pause and restore a project, the restored database includes the latest
## Migrate your project
-Migrating projects can be achieved using standard PostgreSQL tooling. This is particularly useful for older projects (e.g. to use a newer Postgres version).
+Migrating projects can be achieved using the Supabase CLI. This is particularly useful for older projects (e.g. to use a newer Postgres version).
### Before you begin
- Install [Postgres](https://www.postgresql.org/download/) so you can run `psql` and `pg_dump`.
+- Install [Supabase CLI](https://supabase.com/docs/guides/cli#installation).
- Create a new [Supabase project](https://app.supabase.com).
- Store the old project's database URL as `$OLD_DB_URL` and the new project's as `$NEW_DB_URL`.
-### Migrate the database
-
-1. Enable [Database Webhooks](https://app.supabase.com/project/_/database/hooks) in your new project if you enabled them in your old project.
-2. In your new project, enable all extensions that were enabled in your old project.
-3. Run the following command from your terminal:
-
-```sh
-set -euo pipefail
-
-pg_dump \
- --clean \
- --if-exists \
- --quote-all-identifiers \
- --exclude-table-data 'storage.objects' \
- --exclude-schema 'extensions|graphql|graphql_public|net|pgbouncer|pgsodium|pgsodium_masks|realtime|supabase_functions|pg_toast|pg_catalog|information_schema' \
- --schema '*' \
- --dbname "$OLD_DB_URL" \
-| sed 's/^DROP SCHEMA IF EXISTS "auth";$/-- DROP SCHEMA IF EXISTS "auth";/' \
-| sed 's/^DROP SCHEMA IF EXISTS "storage";$/-- DROP SCHEMA IF EXISTS "storage";/' \
-| sed 's/^CREATE SCHEMA "auth";$/-- CREATE SCHEMA "auth";/' \
-| sed 's/^CREATE SCHEMA "storage";$/-- CREATE SCHEMA "storage";/' \
-| sed 's/^ALTER DEFAULT PRIVILEGES FOR ROLE "supabase_admin"/-- ALTER DEFAULT PRIVILEGES FOR ROLE "supabase_admin"/' \
-> dump.sql
+### Backup your old database
+1. Run the following command from your terminal:
+
+```bash
+supabase db dump --db-url "$OLD_DB_URL" -f roles.sql --role-only
+supabase db dump --db-url "$OLD_DB_URL" -f schema.sql
+supabase db dump --db-url "$OLD_DB_URL" -f data.sql --data-only
+```
+
+### Restore to your new project
+
+In your new project:
+
+1. Enable [Database Webhooks](https://app.supabase.com/project/_/database/hooks) if you enabled them in your old project.
+2. Enable any [extensions](https://app.supabase.com/project/_/database/extensions) that were enabled in your old project.
+3. Create any [custom roles](https://app.supabase.com/project/_/database/roles) that were created in your old project.
+
+Then run the following command from your terminal:
+
+```bash
psql \
--single-transaction \
--variable ON_ERROR_STOP=1 \
- --file dump.sql \
+ --file schema.sql \
+ --file data.sql \
--dbname "$NEW_DB_URL"
```