Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save duchri66/42b6517b20d908a64943b70d2dcae4ae to your computer and use it in GitHub Desktop.
Save duchri66/42b6517b20d908a64943b70d2dcae4ae to your computer and use it in GitHub Desktop.
How to backup a AWX postgres database in docker.
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