Grafana Alerts Backup
This role backs up all Grafana alert rules using the API to dual NAS storage.
Overview
This role backs up all Grafana alert rules using the API to dual NAS storage. It exports alerts in YAML provisioning format, organized by folder, and automatically manages retention by keeping only the last 5 backups per NAS. The backup format is compatible with Grafana’s alert rule provisioning, making restoration straightforward.
What This Role Does
- Ensures backup directories exist on both NAS mount points
- Retrieves folder list from Grafana API (
/api/folders) - Creates temporary directory for staging backup files
- Retrieves all alert rules from Grafana Provisioning API (
/api/v1/provisioning/alert-rules) - Groups alert rules by folder and saves each as YAML file
- Skips empty folders (folders with no alert rules)
- Creates timestamped tar.gz archive of all YAML files
- Copies archive to both NAS devices
- Cleans up temporary files and local archive
- Removes old backups, keeping only the 5 most recent per NAS
Role Variables
| Variable | Description |
|---|---|
vault_grafana_ansibleuser_api_token | Grafana API token (from vault) |
grafana_alerts_backup_host | Grafana host and port |
grafana_alerts_backup_validate_certs | Validate SSL certificates |
grafana_alerts_backup_syno_mount_point | Synology NAS destination |
grafana_alerts_backup_prxmxomv_mount_point | Proxmox OMV NAS destination |
Notes
- Backup format is Grafana YAML provisioning format, compatible with
grafana_alerts_restore - Contact points and notification policies are NOT included (alert rules only)
- Each NAS independently retains the last 5 backups