Skip to content

Commit bfa1af2

Browse files
oliricecharislam
andauthored
Document how to restore a project backup locally (supabase#29674)
* document how to restore a project backup locally * fix spelling error * Update apps/docs/content/guides/platform/migrating-and-upgrading-projects.mdx Co-authored-by: Charis <[email protected]> * Update apps/docs/content/guides/platform/migrating-and-upgrading-projects.mdx Co-authored-by: Charis <[email protected]> * Update apps/docs/content/guides/platform/migrating-and-upgrading-projects.mdx Co-authored-by: Charis <[email protected]> * Update apps/docs/content/guides/platform/migrating-and-upgrading-projects.mdx Co-authored-by: Charis <[email protected]> * Update apps/docs/content/guides/platform/migrating-and-upgrading-projects.mdx Co-authored-by: Charis <[email protected]> * Update apps/docs/content/guides/platform/migrating-and-upgrading-projects.mdx Co-authored-by: Charis <[email protected]> * show where to get image version * prettier * resolve feedback on back restore doc * document purpose of local restore. note storage objects download --------- Co-authored-by: Charis <[email protected]>
1 parent d455cda commit bfa1af2

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

apps/docs/content/guides/platform/migrating-and-upgrading-projects.mdx

+50-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ During the 90-day restore window a paused project can be restored to the platfor
7777
src="/docs/img/guides/platform/paused-90-day.png"
7878
/>
7979

80-
After the 90-day restore window, you can download your project's backup file from the project dashboard. This backup is compatible with [pg_restore](https://www.postgresql.org/docs/current/app-pgrestore.html). You can extract your data from it, or attempt to manually restore the project.
80+
After the 90-day restore window, you can download your project's backup file, and Storage objects from the project dashboard. See [restoring a backup locally](#restoring-a-downloaded-backup-locally) for instructions on how to load that backup locally to recover your data.
8181

8282
<Image
8383
zoomable
@@ -93,6 +93,54 @@ If you upgrade to a paid plan while your project is paused, any expired one-clic
9393
src="/docs/img/guides/platform/paused-paid-tier.png"
9494
/>
9595

96+
#### Restoring a Downloaded Backup Locally
97+
98+
If the 90 day project restore window has expired but you need to access data contained within your project using SQL, you can attempt to restore the project into a local Postgres instance. Supabase publishes tooling that can be used for that purpose. Be aware that this workflow does not produce a complete Supabase environment with REST/Auth/Storage. Instead, it creates a standalone Postgres instance that is maximally compatible with your project's backup file to assist with recovering your data.
99+
100+
Downloaded backups are plain text SQL files that can be executed in Postgres to restore your project's schema and data. If you need you access data within a backup we recommend restoring into a Postgres instance built using the Supabase open source build tooling to ensure that the local instance is as similar to the original project as possible. Here are the steps to start Supabase Postgres locally and restore the backup:
101+
102+
Install [nix](https://nixos.org/):
103+
104+
```sh
105+
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
106+
```
107+
108+
To identify your project's backup image version, reference the backup's download button following the `PG:` prefix:
109+
110+
<Image
111+
zoomable
112+
alt="Project Paused: 90 Days Remaining"
113+
src="/docs/img/guides/platform/paused-dl-image-version.png"
114+
/>
115+
116+
Given Postgres version `15.6.1.115`, start Postgres locally with the nix command:
117+
118+
```sh
119+
nix run 'github:supabase/postgres?ref=15.6.1.115#start-server' 15
120+
```
121+
122+
where `15` refers to the backup's Postgres major version.
123+
124+
Note that the earliest Supabase Postgres version that supports a direct reference is `15.6.1.115`. If you don't know your roject's Postgres version or it is lower than `15.6.1.115` then omit the `ref` option to build our most recent image:
125+
126+
```sh
127+
nix run 'github:supabase/postgres#start-server' -- 15
128+
```
129+
130+
Then restore the backup file from a separate shell session:
131+
132+
```sh
133+
nix run github:supabase/postgres#start-client -- --file <BACKUP FILE>
134+
```
135+
136+
Which loads the backup into Postgres and drops you into a [psql](https://www.postgresql.org/docs/current/app-psql.html) prompt. For `start-client` you do not need to provide a reference to the backup's Postgres version.
137+
138+
Once your project has been restored, connect to it with your preferred Postgres tooling using `host=localhost`, `user=postgres`, `port=5432`, and an empty password. This will allow you to inspect your saved data and export whatever is necessary.
139+
140+
Errors encountered during the restore process are logged to the console by the `start-server` process. Review those errors and edit the backup file as needed until the project restores successfully. The backup file is a plain text sequence of SQL statements that recreate your database. To resolve common error classes like `relation "xxx" does not exist`, identify the line raising the exception and shuffle the `create ... "xxx"` statement before it. A failed restore leaves artifacts on the Postgres server so be sure to restart the `start-server` process between restore attempts.
141+
142+
A Postgres database started with `start-server` command is not production ready and should never be used outside a local development workflow.
143+
96144
#### Disk sizing
97145

98146
When upgrading, the Supabase platform will "right-size" your disk based on the current size of the database. For example, if your database is 100GB in size, and you have a 200GB disk, the upgrade will reduce the disk size to 120GB (1.2x the size of your database).
@@ -148,7 +196,7 @@ Supabase performs extensive pre- and post-upgrade validations to ensure that the
148196

149197
## Migrate your project
150198

151-
Migrating projects can be achieved using the Supabase CLI. This is particularly useful for older projects (e.g. to use a newer Postgres version).
199+
Migrating projects can be achieved using the Supabase CLI. This is particularly useful for older projects (for example to use a newer Postgres version).
152200

153201
### Before you begin
154202

Loading
Loading

0 commit comments

Comments
 (0)