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

31 lines
999 B
Plaintext
Raw Normal View History

2022-04-29 11:00:10 +02:00
#!/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 }} \
2024-01-04 17:00:34 +01:00
/usr/pgsql-16/bin/pg_dump \
2022-04-29 11:00:10 +02:00
--clean \
--create \
--username={{ squashtm_db_user | quote }} \
--host={{ squashtm_db_server | quote }} \
--port={{ squashtm_db_port }} \
{{ squashtm_db_name }} | \
{% else %}
2024-01-04 17:00:34 +01:00
su - postgres -c "/usr/pgsql-16/bin/pg_dump --clear {{ squashtm_db_name }}" | \
2022-04-29 11:00:10 +02:00
{% 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 %}