SupabaseS
Supabase8mo ago
Marc

Having issues restoring a database from one project to another

--------------------------------------------------------------------------------------------------------
EDIT: Looks like i did not read the documentation properly, and there is an entry about migrating storage objects, which sounds like it will solve my issue, sorry!
---------------------------------------------------------------------------------------------------------------

Hello everyone,

I want to set up a smooth workflow for restoring one database from one project to another database in another project.

I have been following this guide:
https://supabase.com/docs/guides/platform/migrating-within-supabase/backup-restore

The target database is succesfully reset using supabase db reset

However, i keep running into an issue when restoring data.sql:
psql:data.sql:143730: ERROR:  duplicate key value violates unique constraint "buckets_pkey"
DETAIL:  Key (id)=(profile-images) already exists.
CONTEXT:  COPY buckets, line 1


the command i use to restore is:
psql --single-transaction --variable ON_ERROR_STOP=1 --file roles.sql --file schema.sql --command 'SET session_replication_role = replica' --file data.sql --dbname $cstarget 

where $cstarget is my target database connection string

and the way i dumped the .sql files was:

supabase db dump --db-url $cssource -f roles.sql --role-only

supabase db dump --db-url $cssource  -f schema.sql

supabase db dump --db-url $cssource  -f data.sql --use-copy --data-only

where $cssource is my source db connection string.

I did not get any errors when dumping, i have gathered from previous posts in here, that it is related to storage and auth not getting reset using supabase db reset, however i don't see how i am then supposed to properly reset(and ideally, restore) these?

Ideally i want to reset and restore everything in the target database, so that it's 1:1 with the source database
Learn how to backup and restore projects using the Supabase CLI
Was this page helpful?