Skip to content

Commit

Permalink
Adding keepalive while doing pg_dump (#1580)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealHaoLiu committed Oct 10, 2023
1 parent a7cfbe2 commit 92639c1
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions roles/backup/tasks/postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,27 @@
namespace: "{{ backup_pvc_namespace }}"
pod: "{{ ansible_operator_meta.name }}-db-management"
command: |
bash -c """
bash -c "
function end_keepalive {
rc=$?
rm -f \"$1\"
kill $(cat /proc/$2/task/$2/children 2>/dev/null) 2>/dev/null || true
wait $2 || true
exit $rc
}
keepalive_file=\"$(mktemp)\"
while [[ -f \"$keepalive_file\" ]]; do
echo 'Dumping data from database...'
sleep 60
done &
keepalive_pid=$!
trap 'end_keepalive \"$keepalive_file\" \"$keepalive_pid\"' EXIT SIGINT SIGTERM
echo keepalive_pid: $keepalive_pid
set -e -o pipefail
PGPASSWORD='{{ awx_postgres_pass }}' {{ pgdump }} > {{ backup_dir }}/tower.db
set +e +o pipefail
echo 'Successful'
"""
"
register: data_migration
no_log: "{{ no_log }}"
failed_when: "'Successful' not in data_migration.stdout"

0 comments on commit 92639c1

Please sign in to comment.