Instructions/Script to backup and restore PostgresQL databases from docker containers
#1
Open
opened 3 years ago by youainti
·
5 comments
Loading…
Reference in New Issue
There is no content yet.
Delete Branch '%!s(<nil>)'
Deleting a branch is permanent. It CANNOT be undone. Continue?
something similar to
Bash script to backup and restore PostgresQL databasesto Bash script to backup and restore PostgresQL databases from docker containers 3 years agoApproach that I favor:
Import:
exec gzip --decompress --stdout --keep /backup/export_name | pgsql ${USERNAME} ${DATABASE} ${PASSWORD}Include an option for the started container to have volumes attached.
Note: The code above is just an example.
This doesn't need to be a bash script necessarily, it could be just a set of commands to run. It could even be based on a set of temporary environment variables.
Bash script to backup and restore PostgresQL databases from docker containersto Instructions/Script to backup and restore PostgresQL databases from docker containers 3 years agoEXPORT
To dump the database, run the following within the database container to create the backup:
outside the database container, run the following to export the backup
IMPORT
Start container and do one of the following
Adding a volume to docker container
This involves either adding the backup file to a volume in docker compose or restarting the container with
docker stopanddocker start -v ...docker composeAdd to the docker-compose.yaml file
Docker startwhen starting the postgres container with docker
TODO: add some details here.
Copying the file over
Once the file is accessible in the container:
Note that the
gzip -koption will keep the original compressed file instead of getting rid of it.To clean up we would do:
How to turn this into a script or better instructions?
Used this successfully to restore AACT.