feat: add backup role using restic

This commit is contained in:
2026-07-09 15:51:45 +02:00
parent 04e38f42b5
commit 8d96529d8f
4 changed files with 71 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
---
- name: Install Restic
ansible.builtin.apt:
name: restic
state: present
become: true
- name: Deploy restic backup script
ansible.builtin.template:
src: restic-backup.sh.j2
dest: /usr/local/bin/restic-backup.sh
mode: "0700" # Only root can read/execute this because it contains secrets
- name: Deploy restic systemd service
ansible.builtin.template:
src: restic-backup.service.j2
dest: /etc/systemd/system/restic-backup.service
mode: "0644"
- name: Deploy restic systemd timer
ansible.builtin.template:
src: restic-backup.timer.j2
dest: /etc/systemd/system/restic-backup.timer
mode: "0644"
- name: Enable and start backup timer
ansible.builtin.systemd:
name: restic-backup.timer
enabled: yes
state: started
daemon_reload: yes
@@ -0,0 +1,7 @@
[Unit]
Description=Run Restic Backup
After=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/restic-backup.sh
@@ -0,0 +1,23 @@
#!/bin/bash
## Ansible managed
## Secrets are passed via Ansible Vault variables
export RESTIC_REPOSITORY="{{ vault_restic_repo_url }}"
export RESTIC_PASSWORD="{{ vault_restic_password }}"
export AWS_ACCESS_KEY_ID="{{ vault_aws_access_key }}"
export AWS_SECRET_ACCESS_KEY="{{ vault_aws_secret_key }}"
set -e
echo "Starting Restic Backup at $(date)"
## Run the backup (docker volumes & config files)
restic backup \
/etc \
/opt/docker-data \
--exclude /opt/docker-data/tmp \
--cleanup-cache
restic forget --prune --keep-daily 7 --keep-weekly 4 --keep-monthly 6
echo "Restic backup completed at $(date)"
@@ -0,0 +1,10 @@
[Unit]
Description=Run Restic Backup Daily at 4:00 AM
[Timer]
OnCalendar=*-*-* 04:00:00
Persistent=true
RandomizedDelaySec=1800
[Install]
WantedBy=timers.target