Skip to content

Instantly share code, notes, and snippets.

@katopz
Created September 26, 2020 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katopz/1883ba28e64aaf582a71772dca8dfd98 to your computer and use it in GitHub Desktop.
Save katopz/1883ba28e64aaf582a71772dca8dfd98 to your computer and use it in GitHub Desktop.
Restore postgres from backup file in docker
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