Skip to content

Instantly share code, notes, and snippets.

@mtcoffee
Created May 28, 2024 18:43
Show Gist options
  • Save mtcoffee/2bd5f6f5e3fbee8289c6c0d3f1b02a40 to your computer and use it in GitHub Desktop.
Save mtcoffee/2bd5f6f5e3fbee8289c6c0d3f1b02a40 to your computer and use it in GitHub Desktop.
How to Backup/Migrate/Restore AWX
####################How to Backup/Migrate/Restore AWX#############################
#1.Create a postgres backup on the old system
#In K8s
kubectl -n awx exec ansible-awx-postgres-15-0 -- bash -c "pg_dump -U awx awx --format=c" > aws_pg_backup.sql
#In Docker
docker exec tools_postgres_1 /bin/bash -c "pg_dump -U awx awx --format=c" > dockerbackup1.sql
#2. Find the secret_key data from old setup
#In K8s
kubectl get secret ansible-awx-secret-key -n awx -o jsonpath="{.data.secret_key}" | base64 --decode
#it is also stored in the file /etc/tower/SECRET_KEY in the ansible-awx-task pod
#In Docker
docker exec tools_awx_1 cat /etc/tower/SECRET_KEY
####################RESTORING ON A NEW AWX/K8s INSTANCE#########################
#1. Bring it all down
kubectl -n awx scale deployment awx-operator-controller-manager --replicas=0
kubectl -n awx scale deployment ansible-awx-task --replicas=0
kubectl -n awx scale deployment ansible-awx-web --replicas=0
#2. Restore the Key
secret=<secret from steps above>
kubectl patch secret ansible-awx-secret-key -n awx -p '{"data": {"secret_key": "'"$(echo -n $secret | base64)"'"}}'
#3. Restore the DB
kubectl -n awx exec -it ansible-awx-postgres-15-0 -- psql -U postgres -d postgres -c "ALTER USER awx CREATEDB;"
kubectl -n awx exec -it ansible-awx-postgres-15-0 -- dropdb -U awx awx
kubectl -n awx exec -it ansible-awx-postgres-15-0 -- createdb -U awx -T template0 awx
kubectl -n awx exec -it ansible-awx-postgres-15-0 -- pg_restore -U awx -d awx < aws_pg_backup.sql
#4. Bring it online.
kubectl -n awx scale deployment awx-operator-controller-manager --replicas=1
kubectl -n awx scale deployment ansible-awx-task --replicas=1
kubectl -n awx scale deployment ansible-awx-web --replicas=1
#5. If moving to a new version of AWX run "awx-manage migrate --noinput"
awxPod=`kubectl get pods -n awx --no-headers | grep '^ansible-awx-web' | awk '{print $1}'`
kubectl exec -n awx -it pod/$awxPod --container ansible-awx-web -- awx-manage migrate --noinput
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment