From cfd0c0100d938a747868c98c4cb5d23694a950e1 Mon Sep 17 00:00:00 2001 From: Christian Steinle Date: Fri, 19 Nov 2021 12:13:06 +0100 Subject: [PATCH] Extend cleanup of original backup files and do the logrotate. --- odroid.yaml | 60 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/odroid.yaml b/odroid.yaml index b5b2128..8422af3 100644 --- a/odroid.yaml +++ b/odroid.yaml @@ -78,30 +78,6 @@ loop_control: label: "{{ item.item[0] }} {{ item.item[1] }}" - - name: Store the yearly backups - copy: - remote_src: true - src: "{{ backup_dir }}/{{ item }}/{{ ansible_date_time.iso8601_basic_short }}.sql.gz" - dest: "{{ backup_dir }}/{{ item }}/yearly/{{ ansible_date_time.iso8601_basic_short }}.sql.gz" - loop: "{{ databases }}" - when: (ansible_date_time.day == "01" and ansible_data_time.month == "01") - - - name: Store the monthly backups - copy: - remote_src: true - src: "{{ backup_dir }}/{{ item }}/{{ ansible_date_time.iso8601_basic_short }}.sql.gz" - dest: "{{ backup_dir }}/{{ item }}/monthly/{{ ansible_date_time.iso8601_basic_short }}.sql.gz" - loop: "{{ databases }}" - when: (ansible_date_time.day == "01" and ansible_data_time.month != "01") - - - name: Store the weekly backups - copy: - remote_src: true - src: "{{ backup_dir }}/{{ item }}/{{ ansible_date_time.iso8601_basic_short }}.sql.gz" - dest: "{{ backup_dir }}/{{ item }}/weekly/{{ ansible_date_time.iso8601_basic_short }}.sql.gz" - loop: "{{ databases }}" - when: (ansible_date_time.weekday_number == "7") - - name: Search for the created backups find: paths: "{{ backup_dir }}/{{ item }}" @@ -111,6 +87,36 @@ register: backup_files loop: "{{ systems }}" + - 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 == "7") + loop_control: + label: "{{ item.path }}" + - name: Store the daily backup copy: remote_src: true @@ -123,9 +129,11 @@ - name: Cleanup original backup files file: - path: "{{ backup_dir }}/{{ item }}/*" + path: "{{ item.path }}" state: absent - loop: "{{ systems }}" + with_items: "{{ backup_files.results | map(attribute='files') | list }}" + loop_control: + label: "{{ item.path }}" - name: Find old daily backups find: