ansible-roles/roles/squash_tm/templates/pre-backup.j2

31 lines
999 B
Django/Jinja

#!/bin/sh
set -eo pipefail
{% if squashtm_db_engine == 'postgres' %}
{% if squashtm_db_server not in ['localhost', '127.0.0.1'] %}
PGPASSWORD={{ squashtm_db_pass | quote }} \
/usr/pgsql-16/bin/pg_dump \
--clean \
--create \
--username={{ squashtm_db_user | quote }} \
--host={{ squashtm_db_server | quote }} \
--port={{ squashtm_db_port }} \
{{ squashtm_db_name }} | \
{% else %}
su - postgres -c "/usr/pgsql-16/bin/pg_dump --clear {{ squashtm_db_name }}" | \
{% endif %}
zstd -c > {{ squashtm_root_dir }}/backup/{{ squashtm_db_name }}.sql.zst
{% else %}
/usr/bin/mysqldump \
{% if squashtm_db_server not in ['localhost', '127.0.0.1'] %}
--user={{ squashtm_db_user | quote }} \
--password={{ squashtm_db_pass | quote }} \
--host={{ squashtm_db_server | quote }} \
--port={{ squashtm_db_port }} \
{% endif %}
--quick --single-transaction \
--add-drop-table {{ squashtm_db_name }} | \
zstd -c > {{ squashtm_root_dir }}/backup/{{ squashtm_db_name }}.sql.zst
{% endif %}