infra-role-gitea/tasks/backup.yml

20 lines
879 B
YAML

---
- name: 'Create timer for Gitea backup: {{ gitea_db_backup_service_name }}'
include_role: name=systemd-timer
vars:
systemd_timer_name: '{{ gitea_db_backup_service_name }}'
systemd_timer_description: 'Dump Gitea PostgreSQL database.'
systemd_timer_user: '{{ gitea_db_backup_user }}'
systemd_timer_frequency: '{{ gitea_db_backup_frequency }}'
systemd_timer_timeout_sec: '{{ gitea_db_backup_timeout }}'
systemd_timer_after_extra: 'docker.service'
systemd_timer_start_on_creation: false
systemd_timer_script_content: |
#!/usr/bin/env bash
BKP_DIR="{{ gitea_db_cont_vol }}/backup/{{ gitea_db_name }}"
rm -vfr "${BKP_DIR}"
/usr/bin/docker exec -i {{ gitea_db_cont_name }} \
pg_dump -F directory -f "/backup/{{ gitea_db_name }}" \
-U {{ gitea_db_user }} {{ gitea_db_name }}
chmod 750 -R "${BKP_DIR}"