Last active
March 16, 2021 02:05
-
-
Save narankhetani/380569770d46f119b4cc314c2bf3f77f to your computer and use it in GitHub Desktop.
How to backup a AWX postgres database 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
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' |
The instructions here don't seem to work now, dumped it with:
# docker exec -u awx awx_postgres pg_dump -Fc awx > /var/lib/awx/projects/awx-db_`date +%y.%m.%d_%H.%M.%S`.dump
Restore it with:
root@AWX-2-panel:~# docker stop awx_task
awx_task
root@AWX-2-panel:~# docker stop awx_web
awx_web
root@AWX-2-panel:~# docker exec -u postgres awx_postgres psql postgres awx -c 'ALTER DATABASE "awx" RENAME TO "awx-db_21.01.04_13.02.09"'
root@AWX-2-panel:~# docker exec awx_postgres psql -U awx -l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
--------------------------+-------+----------+------------+------------+-------------------
awx-db_21.01.04_13.02.09 | awx | UTF8 | en_US.utf8 | en_US.utf8 |
postgres | awx | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | awx | UTF8 | en_US.utf8 | en_US.utf8 | =c/awx +
| | | | | awx=CTc/awx
template1 | awx | UTF8 | en_US.utf8 | en_US.utf8 | =c/awx +
| | | | | awx=CTc/awx
(4 rows)
root@AWX-2-panel:~# docker exec -d awx_postgres mkdir /pgrestore
root@AWX-2-panel:~# docker cp /root/awx-db_21.01.04_13.02.09.dump awx_postgres:pgrestore
root@AWX-2-panel:~# docker exec awx_postgres pg_restore -U awx -C -c /pgrestore/awx-db_21.01.04_13.02.09.dump
pg_restore: [archiver] input file does not appear to be a valid archive (too short?)
Trying to move the application from one Debian 10 machine to another Debian 10 machine. Upgrading from 15.01 to 16.0.0.
After installing AWX with the same credentials, I cleared out /var/lib/awx/projects/ and updated it's contents with that of the previous server, then tried to perform this DB import.
These seemed to work:
# docker exec -t awx_postgres pg_dump -U awx awx > /var/lib/awx/projects/awx-dump.sql
# docker exec -t awx_postgres psql -U awx awx < /var/lib/awx/projects/awx-dump.sql
or
root@AWX-3-panel:~# docker stop awx_task
awx_task
root@AWX-3-panel:~# docker stop awx_web
awx_web
root@AWX-3-panel:~# cp /var/lib/awx/projects/awx-dump.sql /root/.awx/pgdocker/10/data/
root@AWX-3-panel:~# docker exec -it awx_postgres /bin/bash
root@ce48e2584014:/#
root@ce48e2584014:/# dropdb -U awx awx
root@ce48e2584014:/# createdb -U awx awx
root@ce48e2584014:/# psql -U awx awx < /var/lib/postgresql/data/awx-dump.sql
root@ce48e2584014:/# exit
exit
root@AWX-3-panel:~# docker start awx_task
awx_task
root@AWX-3-panel:~# docker start awx_web
awx_web
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It makes managing your evolving books easy (especially if you flag it to check for the latest code change before any job run) but I noticed it makes. The job progress window a bit lazy (had to refresh to see progress realtime). Ymmv