More backup stuff

This commit is contained in:
Bradley Bickford 2025-08-20 17:45:57 -04:00
parent 16e9c32e41
commit 846496d618
2 changed files with 23 additions and 0 deletions

View File

@ -35,6 +35,7 @@ all:
3331636339356236330a333330373264306163393162386330393763613332376261373433303035
65633034366439343232356639346665326234666630633063616437376131396463
backup_location: "/backup/pfsense"
backup_number_to_keep: 10
boardwalk:
ansible_host: "10.77.7.2"
backup_url: "10.77.7.2"
@ -47,6 +48,7 @@ all:
6566663062336566320a323536303233393431363263313933643839303435356266656136343438
35306638356564333962656433323735656136386130373233393765616265306636
backup_location: "/backup/pfsense"
backup_number_to_keep: 10
children:
docker_nodes:
hosts:

View File

@ -82,6 +82,27 @@
dest: "{{ backup_location }}/{{ inventory_hostname }}_{{ now().strftime('%Y%m%d%H%M%S') }}.xml"
changed_when: false
no_log: "{{ pfsense_backup_disable_logging | default(false) }}"
- name: Find all PFSense backups for the current host
ansible.builtin.find:
paths: "{{ backup_location }}"
patterns: "{{ inventory_hostname }}*"
register: all_pfsense_backups
- name: If too many backups kept
when: all_pfsense_backups | length > backup_number_to_keep
block:
- name: Get the oldest file paths
ansible.builtin.set_fact:
oldest_file_paths: >-
{{ (all_pfsense_backups.files | sort(attribute='mtime'))[:all_pfsense_backups.files | length - backup_number_to_keep] |
map(attribute=path) | list }}
- name: Remove the files
ansible.builtin.file:
path: "{{ item }}"
state: absent
loop: "{{ oldest_file_paths }}"
- name: Docker Infrastructure Compose Backups
hosts: docker_nodes