103 lines
2.5 KiB
YAML
103 lines
2.5 KiB
YAML
---
|
|
# This playbook removes old backups
|
|
- name: Cleanup old backups
|
|
hosts: all
|
|
gather_facts: True
|
|
vars:
|
|
directories:
|
|
- /media/backup/docker
|
|
- /media/backup/strato-production
|
|
|
|
tasks:
|
|
- name: Register all backup directories
|
|
find:
|
|
paths: "{{ item }}"
|
|
file_type: directory
|
|
recurse: false
|
|
register: backup_dirs
|
|
loop: "{{ directories }}"
|
|
|
|
- name: Find old daily backups
|
|
find:
|
|
paths: "{{ item[1].path }}/daily"
|
|
file_type: file
|
|
age: 7d
|
|
age_stamp: mtime
|
|
recurse: false
|
|
register: backup_files
|
|
loop: "{{ backup_dirs.results | subelements('files') }}"
|
|
loop_control:
|
|
label: "{{ item[1].path }}"
|
|
|
|
- name: Delete old daily backups
|
|
file:
|
|
path: "{{ item[1].path }}"
|
|
state: absent
|
|
loop: "{{ backup_files.results | subelements('files') }}"
|
|
loop_control:
|
|
label: "{{ item[1].path }}"
|
|
|
|
- name: Find old weekly backups
|
|
find:
|
|
paths: "{{ item[1].path }}/weekly"
|
|
file_type: file
|
|
age: 4w
|
|
age_stamp: mtime
|
|
recurse: false
|
|
register: backup_files
|
|
loop: "{{ backup_dirs.results | subelements('files') }}"
|
|
loop_control:
|
|
label: "{{ item[1].path }}"
|
|
|
|
- name: Delete old weekly backups
|
|
file:
|
|
path: "{{ item[1].path }}"
|
|
state: absent
|
|
loop: "{{ backup_files.results | subelements('files') }}"
|
|
loop_control:
|
|
label: "{{ item[1].path }}"
|
|
|
|
- name: Find old monthly backups
|
|
find:
|
|
paths: "{{ item[1].path }}/monthly"
|
|
file_type: file
|
|
age: 48w
|
|
age_stamp: mtime
|
|
recurse: false
|
|
register: backup_files
|
|
loop: "{{ backup_dirs.results | subelements('files') }}"
|
|
loop_control:
|
|
label: "{{ item[1].path }}"
|
|
|
|
- name: Delete old monthly backups
|
|
file:
|
|
path: "{{ item[1].path }}"
|
|
state: absent
|
|
loop: "{{ backup_files.results | subelements('files') }}"
|
|
loop_control:
|
|
label: "{{ item[1].path }}"
|
|
|
|
- name: Find old yearly backups
|
|
find:
|
|
paths: "{{ item[1].path }}/yearly"
|
|
file_type: file
|
|
age: 156w
|
|
age_stamp: mtime
|
|
recurse: false
|
|
register: backup_files
|
|
loop: "{{ backup_dirs.results | subelements('files') }}"
|
|
loop_control:
|
|
label: "{{ item[1].path }}"
|
|
|
|
- name: Delete old yearly backups
|
|
file:
|
|
path: "{{ item[1].path }}"
|
|
state: absent
|
|
loop: "{{ backup_files.results | subelements('files') }}"
|
|
loop_control:
|
|
label: "{{ item[1].path }}"
|
|
|
|
- name: Include the run next playbook
|
|
import_playbook: run-next.yaml
|
|
vars:
|
|
to_do: odroid |