infra-role-grafana/tasks/backup.yml

29 lines
1.0 KiB
YAML

---
- name: Create backups directory
file:
path: '{{ grafana_backup_dir }}'
owner: '{{ grafana_backup_user }}'
group: 'adm'
state: directory
mode: 0750
- name: Create backup timer service
include_role: name=systemd-timer
vars:
systemd_timer_description: 'Grafana batabase backup'
systemd_timer_name: '{{ grafana_service_name }}-backup'
systemd_timer_user: '{{ grafana_backup_user }}'
systemd_timer_frequency: '{{ grafana_backup_frequency }}'
systemd_timer_timeout_sec: '{{ grafana_backup_timeout_sec }}'
systemd_timer_work_dir: '{{ grafana_backup_dir }}'
systemd_timer_start_on_creation: true
systemd_timer_script_content: |
#!/usr/bin/env bash
MAX_KEPT={{ grafana_backup_max_kept }}
DB_PATH="{{ grafana_cont_vol }}/lib/grafana.db"
TSAMP=$(date -u +%Y%m%d-%H%M%S)
echo "Saving Grafana database..."
gzip -c "${DB_PATH}" > "grafana-${TSAMP}.db.gz"
echo "Cleaning up old archives..."
rm -vf $(ls -Art | head -n -${MAX_KEPT})