TwentyT
Twenty2y ago
12 replies
greg [iero]

Backup/restore/Migrate database

I have a local server in 0.3.2 and a (future) prod server in 0.3.3.

I would like to move my database from the first one to the second one.

Ok so I dumped DB:

pg_dump -U twenty -h localhost -p 5432 -Fc default > db_twenty.dump 


I scp the dump to the server, copy in docker, and connect to this docker container:

docker cp ../db_twenty.dump twenty-db-1:
docker exec -it twenty-db-1 /bin/bash


I removed existing database and create a fresh one:

dropdb -U twenty -h localhost -p 5432 default
createdb  -U twenty -h localhost -p 5432 default


Next I restore the database

cd

pg_restore -U twenty -h localhost -p 5432 -C --clean --create --if-exists -d default db_twenty.dump 
Password: 
pg_restore: error: could not execute query: ERROR:  cannot drop the currently open database
Command was: DROP DATABASE IF EXISTS "default";
pg_restore: error: could not execute query: ERROR:  database "default" already exists
Command was: CREATE DATABASE "default" WITH TEMPLATE = template0 ENCODING = 'UTF8' LOCALE_PROVIDER = libc LOCALE = 'en_US.UTF-8';


pg_restore: warning: errors ignored on restore: 2


In server side:

docker exec -it twenty-server-1 sh

/app/packages/twenty-server $ yarn database:migrate:prod


And restart:

docker-compose restart


It seems to work. Do you think I did it the right way? Any improvement to that process?
Was this page helpful?