*untested* Revamp of backup protocol and some cleanup

This commit is contained in:
Bradley committed 2026-10-17 22:46:08 -04:00
1 parent dc23952921
commit 829f433656
8 files changed
+196 -193

No files matched your search

@@ -1,2 +1,2 @@
---
backup_rules: ""
docker_backup_rules: ""
+17 -10
View File
@@ -2,7 +2,7 @@
- name: Ensure backup rules contains the necessary fields
ansible.builtin.fail:
msg: "You must define {{ backup_rule_checker }} in the backup ruleset"
when: not backup_rules[backup_rule_checker] is defined
when: not docker_backup_rules[backup_rule_checker] is defined
loop:
- container_name
- directories_to_backup
@@ -14,42 +14,49 @@
- name: Make sure backup dir exists
ansible.builtin.file:
path: "{{ backup_rules['backup_dir'] }}"
path: "{{ docker_backup_rules['backup_dir'] }}"
state: directory
recurse: true
- name: Stop the running container
community.docker.docker_container:
name: "{{ backup_rules.container_name }}"
name: "{{ docker_backup_rules.container_name }}"
state: stopped
- name: Archive necessary directories
community.general.archive:
path: "{{ backup_rules.directories_to_backup }}"
path: "{{ docker_backup_rules.directories_to_backup }}"
dest: >-
{{ backup_rules.backup_dir }}/{{ backup_rules.backup_name_prefix }}_{{ now().strftime("%Y%m%d%H%M%S") }}.tar.gz
{{ docker_backup_rules.backup_dir }}/{{ docker_backup_rules.backup_name_prefix }}_{{ now().strftime("%Y%m%d%H%M%S") }}.tar.gz
format: gz
async: 3600
poll: 60
- name: Take a MySQL DB backup if necessary
ansible.builtin.import_role:
name: mysql_backup
vars:
mysql_backup_rules: "{{ docker_backup_rules['mysql_backup'] }}"
when: docker_backup_rules['mysql_backup'] is defined
- name: Start the stopped container
community.docker.docker_container:
name: "{{ backup_rules.container_name }}"
name: "{{ docker_backup_rules.container_name }}"
state: started
- name: Find all files that start with the backup_name_prefix
ansible.builtin.find:
paths: "{{ backup_rules.backup_dir }}"
patterns: "{{ backup_rules.backup_name_prefix }}*"
paths: "{{ docker_backup_rules.backup_dir }}"
patterns: "{{ docker_backup_rules.backup_name_prefix }}*"
register: all_backup_files
- name: If too many backups kept
when: all_backup_files.files | length > backup_rules.max_backups_kept
when: all_backup_files.files | length > docker_backup_rules.max_backups_kept
block:
- name: Get the oldest file paths
ansible.builtin.set_fact:
oldest_file_paths: >-
{{ (all_backup_files.files | sort(attribute='mtime'))[:all_backup_files.files | length - backup_rules.max_backups_kept] |
{{ (all_backup_files.files | sort(attribute='mtime'))[:all_backup_files.files | length - docker_backup_rules.max_backups_kept] |
map(attribute='path') | list }}
- name: Remove the files