From 2b97b661d8535fed19266f15c0598895bf84ecd9 Mon Sep 17 00:00:00 2001 From: emiran-orange <71817149+emiran-orange@users.noreply.github.com> Date: Fri, 5 Aug 2022 17:09:59 +0200 Subject: [PATCH] Move old etcd backup removal after etcd restart (#9147) --- roles/etcd/handlers/backup.yml | 7 ------- roles/etcd/handlers/backup_cleanup.yml | 11 +++++++++++ roles/etcd/handlers/main.yml | 3 +++ 3 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 roles/etcd/handlers/backup_cleanup.yml diff --git a/roles/etcd/handlers/backup.yml b/roles/etcd/handlers/backup.yml index ba6669b3f..d848cdbcb 100644 --- a/roles/etcd/handlers/backup.yml +++ b/roles/etcd/handlers/backup.yml @@ -8,7 +8,6 @@ - Stat etcd v2 data directory - Backup etcd v2 data - Backup etcd v3 data - - Remove old etcd backups when: etcd_cluster_is_healthy.rc == 0 - name: Refresh Time Fact @@ -61,9 +60,3 @@ register: etcd_backup_v3_command until: etcd_backup_v3_command.rc == 0 delay: "{{ retry_stagger | random + 3 }}" - -- name: Remove old etcd backups - shell: - chdir: "{{ etcd_backup_prefix }}" - cmd: "find . -name 'etcd-*' -type d | sort -n | head -n -{{ etcd_backup_retention_count }} | xargs rm -rf" - when: etcd_backup_retention_count >= 0 diff --git a/roles/etcd/handlers/backup_cleanup.yml b/roles/etcd/handlers/backup_cleanup.yml new file mode 100644 index 000000000..e670f46f8 --- /dev/null +++ b/roles/etcd/handlers/backup_cleanup.yml @@ -0,0 +1,11 @@ +--- +- name: Cleanup etcd backups + command: /bin/true + notify: + - Remove old etcd backups + +- name: Remove old etcd backups + shell: + chdir: "{{ etcd_backup_prefix }}" + cmd: "find . -name 'etcd-*' -type d | sort -n | head -n -{{ etcd_backup_retention_count }} | xargs rm -rf" + when: etcd_backup_retention_count >= 0 diff --git a/roles/etcd/handlers/main.yml b/roles/etcd/handlers/main.yml index fa0d273c5..ccf8f8f64 100644 --- a/roles/etcd/handlers/main.yml +++ b/roles/etcd/handlers/main.yml @@ -6,6 +6,7 @@ - etcd | reload systemd - reload etcd - wait for etcd up + - Cleanup etcd backups - name: restart etcd-events command: /bin/true @@ -43,6 +44,8 @@ retries: 60 delay: 1 +- import_tasks: backup_cleanup.yml + - name: wait for etcd-events up uri: url: "https://{% if is_etcd_master %}{{ etcd_address }}{% else %}127.0.0.1{% endif %}:2383/health"