Ian Wienand 8361ab701c
backups: add retirement and purge lists
This adds a retirement and purge list to the borg management role.

The idea here is that when a backed-up host is shut-down, we add its
backup user to the retired list.  On the next ansible run the user
will be disabled on the backup-server and the backup repo marked as
retired.  On the next prune, we will trim the backup to only the last
run to save space.  This gives us a grace period to restore if we
should need to.

When we are sure we don't want the data, we can put it in the purge
list, and the backup repo is removed on the next ansible run (hosts
can go straight into this if we want).  This allows us to have a
review process/history before we purge data.

To test, we create a fake "borg-retired" user on the backup-server,
and give it a simple backup.  This is marked as retired, which is
reflected in the testinfra run of the prune script.  Similarly a
"borg-purge" user is created, and we ensure it's backup dir is
removed.

Documentation is updated.

Change-Id: I5dff0a9d35b11a1f021048a12ecddce952c0c13c
2024-11-08 22:30:49 +11:00

79 lines
1.7 KiB
YAML

- name: Create backup directory
file:
state: directory
path: /opt/backups
- name: Install borg
include_role:
name: install-borg
- name: Install prune script
copy:
src: 'prune-borg-backups.sh'
dest: '/usr/local/bin/prune-borg-backups'
owner: root
group: root
mode: '0755'
- name: Install backup volume monitor
copy:
src: 'backup-volume-monitor.sh'
dest: '/usr/local/bin/backup-volume-monitor'
owner: root
group: root
mode: '0755'
- name: Run backup volume monitor
cron:
name: backup-volume-monitor
state: present
job: '/usr/local/bin/backup-volume-monitor'
minute: '0'
hour: '0'
- name: Install backup verification
copy:
src: 'verify-borg-backups.sh'
dest: '/usr/local/bin/verify-borg-backups'
owner: root
group: root
mode: '0755'
- name: Run backup verification
cron:
name: verify-borg-backups
state: present
job: '/usr/local/bin/verify-borg-backups >> /var/log/verify-borg-backups.log 2>&1'
minute: '0'
hour: '0'
weekday: '0'
- name: Rotate verification logs
include_role:
name: logrotate
vars:
logrotate_file_name: '/var/log/verify-borg-backups.log'
- name: Build all borg users from backup hosts
set_fact:
borg_users: '{{ borg_users + [hostvars[item]["borg_user"]] }}'
with_inventory_hostnames: 'borg-backup:!disabled'
- name: Create borg users
include_tasks: user.yaml
loop: '{{ borg_users }}'
loop_control:
loop_var: borg_user
- name: Remove purged user's backup dirs
file:
name: '/opt/backups/{{ item }}/backup'
state: absent
loop: '{{ borg_purge_users }}'
- name: Disable retired users
include_tasks: retire.yaml
loop: '{{ borg_retire_users }}'
loop_control:
loop_var: borg_user