Store weekly, monthly and yearly backups and clean originals.
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
tasks:
|
||||
- include_vars: vars/semaphore/variable.yaml
|
||||
|
||||
- name: Search for backup directories
|
||||
- name: Search for volume's backup directories
|
||||
become: yes
|
||||
find:
|
||||
paths: "{{ local_backup }}"
|
||||
@@ -61,6 +61,36 @@
|
||||
loop_control:
|
||||
label: "{{ item.path }}"
|
||||
|
||||
- name: Store the yearly backups
|
||||
copy:
|
||||
remote_src: true
|
||||
src: "{{ item.path }}"
|
||||
dest: "{{ item.path | dirname }}/yearly/{{ item.path | basename }}"
|
||||
with_items: "{{ backup_files.results | map(attribute='files') | list }}"
|
||||
when: (ansible_date_time.day == "01" and ansible_data_time.month == "01")
|
||||
loop_control:
|
||||
label: "{{ item.path }}"
|
||||
|
||||
- name: Store the monthly backups
|
||||
copy:
|
||||
remote_src: true
|
||||
src: "{{ item.path }}"
|
||||
dest: "{{ item.path | dirname }}/monthly/{{ item.path | basename }}"
|
||||
with_items: "{{ backup_files.results | map(attribute='files') | list }}"
|
||||
when: (ansible_date_time.day == "01" and ansible_data_time.month != "01")
|
||||
loop_control:
|
||||
label: "{{ item.path }}"
|
||||
|
||||
- name: Store the weekly backups
|
||||
copy:
|
||||
remote_src: true
|
||||
src: "{{ item.path }}"
|
||||
dest: "{{ item.path | dirname }}/weekly/{{ item.path | basename }}"
|
||||
with_items: "{{ backup_files.results | map(attribute='files') | list }}"
|
||||
when: (ansible_date_time.weekday_number == "1")
|
||||
loop_control:
|
||||
label: "{{ item.path }}"
|
||||
|
||||
- name: Store the daily backup
|
||||
copy:
|
||||
remote_src: true
|
||||
@@ -70,3 +100,11 @@
|
||||
when: (ansible_date_time.weekday_number != "1" and ansible_date_time.day != "01")
|
||||
loop_control:
|
||||
label: "{{ item.path }}"
|
||||
|
||||
- name: Cleanup original backup files
|
||||
file:
|
||||
path: "{{ item.path }}"
|
||||
state: absent
|
||||
with_items: "{{ backup_files.results | map(attribute='files') | list }}"
|
||||
loop_control:
|
||||
label: "{{ item.path }}"
|
||||
|
||||
Reference in New Issue
Block a user