Set-OPS-Public/roles/client_backup/templates/sauvegarder.sh.j2

31 lines
959 B
Text
Raw Normal View History

#!/bin/bash
# Géré par Set-OPS (rôle client_backup). Ne pas éditer à la main.
# Sauvegarde applicative du nœud -> dépôt restic hors-nœud (chiffré, dédupliqué).
set -euo pipefail
export RESTIC_REPOSITORY="{{ client_backup_repo }}"
export RESTIC_PASSWORD_FILE="/etc/setops/restic.pass"
# 1. Dumps applicatifs (pg_dump, slapcat, forgejo dump...) vers le staging.
{% for job in client_backup_jobs %}
{% if job.commande is defined %}
install -d -m 0700 "{{ client_backup_staging }}/{{ job.nom }}"
{{ job.commande }}
{% endif %}
{% endfor %}
# 2. Initialiser le dépôt s'il n'existe pas encore.
restic snapshots >/dev/null 2>&1 || restic init
# 3. Snapshot de tous les chemins déclarés.
CHEMINS=(
{% for job in client_backup_jobs %}
{% for c in job.chemins %}
"{{ c }}"
{% endfor %}
{% endfor %}
)
restic backup --host "{{ inventory_hostname }}" --tag setops "${CHEMINS[@]}"
# 4. Rétention.
restic forget {{ client_backup_retention }} --prune