backup: backup each database separately
Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
9951f6a33d
commit
8c10ac4c08
|
@ -9,11 +9,4 @@
|
|||
systemd_timer_timeout_sec: '{{ postgres_ha_backup_timeout }}'
|
||||
systemd_timer_after_extra: 'docker.service'
|
||||
systemd_timer_start_on_creation: false
|
||||
systemd_timer_script_content: |
|
||||
#!/usr/bin/env bash
|
||||
BKP_DIR="{{ postgres_ha_cont_backup_vol }}"
|
||||
rm -vfr "${BKP_DIR}"
|
||||
/usr/bin/docker exec -i {{ postgres_ha_cont_name }} \
|
||||
pg_dump -F directory -f "/backup/{{ postgres_ha_db_name }}" \
|
||||
-U {{ postgres_ha_admin_user }} {{ postgres_ha_db_name }}
|
||||
chmod 750 -R "${BKP_DIR}"
|
||||
systemd_timer_script_content: '{{ lookup("template", "backup.sh.j2") }}'
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/env bash
|
||||
# vim: ft=sh
|
||||
set -e
|
||||
BKP_DIR="{{ postgres_ha_cont_backup_vol }}"
|
||||
DATABASES=(
|
||||
"{{ postgres_ha_db_name }}"
|
||||
{% for db in postgres_ha_databases %}
|
||||
"{{ db.get("name", db.user) }}"
|
||||
{% endfor %}
|
||||
)
|
||||
for DB in "${DATABASES[@]}"; do
|
||||
DB_DUMP_DIR="${BKP_DIR}/${DB}"
|
||||
echo "pg_dump: ${DB} > ${DB_DUMP_DIR}"
|
||||
[[ -d "${DB_DUMP_DIR}" ]] && rm -r "${DB_DUMP_DIR}"
|
||||
docker exec -i {{ postgres_ha_cont_name }} \
|
||||
pg_dump \
|
||||
-F directory \
|
||||
-f "/backup/${DB}" \
|
||||
-U {{ postgres_ha_admin_user }} \
|
||||
"${DB}"
|
||||
done
|
||||
chmod 750 -R "${BKP_DIR}"
|
Loading…
Reference in New Issue