Extend cleanup to weekly and monthly directories.

This commit is contained in:
2021-11-18 12:12:24 +01:00
parent b81a7e7b52
commit 692412c0e9

View File

@@ -101,7 +101,7 @@
- name: Find old daily backups - name: Find old daily backups
find: find:
paths: "{{ backup_dir }}/{{ item }}/daily/" paths: "{{ backup_dir }}/{{ item }}/daily"
file_type: file file_type: file
age: 1h age: 1h
age_stamp: ctime age_stamp: ctime
@@ -125,9 +125,18 @@
age: 1h age: 1h
age_stamp: ctime age_stamp: ctime
patterns: '*.sql.gz' patterns: '*.sql.gz'
recurse: false
register: oldBackups register: oldBackups
loop: "{{ databases }}" loop: "{{ databases }}"
- name: Delete old weekly backups
file:
path: "{{ item.path }}"
state: absent
with_items: "{{ oldBackups.results | map(attribute='files') | list }}"
loop_control:
label: "{{ item.path }}"
- name: Find old monthly backups - name: Find old monthly backups
find: find:
paths: "{{ backup_dir }}/{{ item }}/monthly" paths: "{{ backup_dir }}/{{ item }}/monthly"
@@ -135,5 +144,14 @@
age: 13m age: 13m
age_stamp: ctime age_stamp: ctime
patterns: '*.sql.gz' patterns: '*.sql.gz'
recurse: false
register: oldBackups register: oldBackups
loop: "{{ databases }}" loop: "{{ databases }}"
- name: Delete old monthly backups
file:
path: "{{ item.path }}"
state: absent
with_items: "{{ oldBackups.results | map(attribute='files') | list }}"
loop_control:
label: "{{ item.path }}"