Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restore postgres within a docker?

I create backups like this: docker exec DOCKER pg_dump -U USER -F t DB | gzip > ./FILE.tar.gz

What's the best way to restore the database given that the database runs within a container?

like image 402
user706838 Avatar asked Feb 05 '23 19:02

user706838


1 Answers

For your case:

docker exec -it <CONTAINER> gunzip < backup.tar.gz | pg_restore -U <USER> -F t -d <DB>

Remote restore is also available if your container is public facing and remote connections are allowed in pg_hba.conf for postresql:

gunzip < backup.tar.gz | pg_restore -U <USER> -F t -d <DB> -h <HOST_IP> -p 5432

As a rule of thumb, it is good idea to document your backup and restore commands specific to the project.

like image 118
hurturk Avatar answered Feb 07 '23 10:02

hurturk