Created
September 26, 2020 04:53
-
-
Save katopz/1883ba28e64aaf582a71772dca8dfd98 to your computer and use it in GitHub Desktop.
Restore postgres from backup file in docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker run --name foo-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres | |
docker inspect -f '{{ json .Mounts }}' foo-postgres | python -m json.tool | |
``` | |
[ | |
{ | |
"Destination": "/var/lib/postgresql/data", | |
"Driver": "local", | |
"Mode": "", | |
"Name": "8ce3df1ef910ec01686401a1fc8cdfff729aa2cd88ccac852c436badab7f3dea", | |
"Propagation": "", | |
"RW": true, | |
"Source": "/var/lib/docker/volumes/8ce3df1ef910ec01686401a1fc8cdfff729aa2cd88ccac852c436badab7f3dea/_data", | |
"Type": "volume" | |
} | |
] | |
``` | |
docker cp db.tar foo-postgres:/var/lib/postgresql/data | |
docker exec foo-postgres psql -U postgres -l | |
``` | |
List of databases | |
Name | Owner | Encoding | Collate | Ctype | Access privileges | |
-----------+----------+----------+------------+------------+----------------------- | |
postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 | | |
template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres + | |
| | | | | postgres=CTc/postgres | |
template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres + | |
| | | | | postgres=CTc/postgres | |
(3 rows) | |
``` | |
docker exec foo-postgres pg_restore -U postgres -d postgres /var/lib/postgresql/data/db.tar -c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment