Forked from narankhetani/postgres.docker.backup.txt
Created
November 23, 2018 17:07
-
-
Save yolleksandr/41712641efb4bb44b03e5f0bdd6119ab to your computer and use it in GitHub Desktop.
How to backup a AWX postgres database in docker.
This file contains hidden or 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
To backup: | |
docker exec -u <your_postgres_user> <postgres_container_name> pg_dump -Fc <database_name_here> > db.dump | |
To drop db (Don't do it on production, for test purpose only!!!): | |
docker exec -u <your_postgres_user> <postgres_container_name> psql -c 'DROP DATABASE <your_db_name>' | |
To restore: | |
docker exec -i -u <your_postgres_user> <postgres_container_name> pg_restore -C -d postgres < db.dump | |
working example for awx postgres database | |
backup: | |
docker exec -u postgres postgres pg_dump -Fc awx > `date +%m.%d.%y_%H.%M.%S`_awx_db.dump | |
RESTORE: | |
docker stop awx_task | |
docker stop awx_web | |
docker stop memcached | |
rename current db: | |
docker exec -u postgres postgres psql postgres awx -c 'ALTER DATABASE "awx" RENAME TO "awx_01_03_18"' | |
restore AWX db: | |
docker exec -i -u postgres postgres pg_restore -C -d postgres < 01.03.18_03.17.33_awx_db.dump | |
docker start memcached | |
docker start awx_web | |
docker start awx_task | |
if you are happy with everything you can drop your other database: | |
docker exec -u postgres postgres psql -c 'DROP DATABASE awx_01_03_18' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment