2017-03-16 19:38:13 +00:00
|
|
|
---
|
|
|
|
- name: Backup etcd data
|
|
|
|
command: /bin/true
|
|
|
|
notify:
|
|
|
|
- Refresh Time Fact
|
|
|
|
- Set Backup Directory
|
|
|
|
- Create Backup Directory
|
2017-08-31 15:23:24 +00:00
|
|
|
- Stat etcd v2 data directory
|
2017-03-16 19:38:13 +00:00
|
|
|
- Backup etcd v2 data
|
|
|
|
- Backup etcd v3 data
|
2020-10-23 14:09:57 +00:00
|
|
|
- Remove old etcd backups
|
2017-03-16 19:38:13 +00:00
|
|
|
when: etcd_cluster_is_healthy.rc == 0
|
|
|
|
|
|
|
|
- name: Refresh Time Fact
|
|
|
|
setup: filter=ansible_date_time
|
|
|
|
|
|
|
|
- name: Set Backup Directory
|
|
|
|
set_fact:
|
|
|
|
etcd_backup_directory: "{{ etcd_backup_prefix }}/etcd-{{ ansible_date_time.date }}_{{ ansible_date_time.time }}"
|
|
|
|
|
|
|
|
- name: Create Backup Directory
|
|
|
|
file:
|
|
|
|
path: "{{ etcd_backup_directory }}"
|
|
|
|
state: directory
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0600
|
|
|
|
|
2017-08-31 15:23:24 +00:00
|
|
|
- name: Stat etcd v2 data directory
|
|
|
|
stat:
|
|
|
|
path: "{{ etcd_data_dir }}/member"
|
2021-02-10 13:36:59 +00:00
|
|
|
get_attributes: no
|
|
|
|
get_checksum: no
|
|
|
|
get_mime: no
|
2017-08-31 15:23:24 +00:00
|
|
|
register: etcd_data_dir_member
|
|
|
|
|
2017-03-16 19:38:13 +00:00
|
|
|
- name: Backup etcd v2 data
|
2017-08-31 15:23:24 +00:00
|
|
|
when: etcd_data_dir_member.stat.exists
|
2017-03-23 16:56:30 +00:00
|
|
|
command: >-
|
|
|
|
{{ bin_dir }}/etcdctl backup
|
|
|
|
--data-dir {{ etcd_data_dir }}
|
|
|
|
--backup-dir {{ etcd_backup_directory }}
|
2017-03-16 19:38:13 +00:00
|
|
|
environment:
|
|
|
|
ETCDCTL_API: 2
|
|
|
|
retries: 3
|
2018-08-17 09:05:57 +00:00
|
|
|
register: backup_v2_command
|
|
|
|
until: backup_v2_command.rc == 0
|
2017-03-16 19:38:13 +00:00
|
|
|
delay: "{{ retry_stagger | random + 3 }}"
|
|
|
|
|
|
|
|
- name: Backup etcd v3 data
|
2017-03-23 16:56:30 +00:00
|
|
|
command: >-
|
|
|
|
{{ bin_dir }}/etcdctl
|
|
|
|
snapshot save {{ etcd_backup_directory }}/snapshot.db
|
2017-03-16 19:38:13 +00:00
|
|
|
environment:
|
|
|
|
ETCDCTL_API: 3
|
2020-07-20 14:26:51 +00:00
|
|
|
ETCDCTL_ENDPOINTS: "{{ etcd_access_addresses.split(',') | first }}"
|
2018-03-31 18:06:09 +00:00
|
|
|
ETCDCTL_CERT: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
|
|
|
|
ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
|
2019-03-28 07:18:43 +00:00
|
|
|
ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem"
|
2017-03-16 19:38:13 +00:00
|
|
|
retries: 3
|
2018-08-17 09:05:57 +00:00
|
|
|
register: etcd_backup_v3_command
|
|
|
|
until: etcd_backup_v3_command.rc == 0
|
2017-03-16 19:38:13 +00:00
|
|
|
delay: "{{ retry_stagger | random + 3 }}"
|
2020-10-23 14:09:57 +00:00
|
|
|
|
|
|
|
- name: Remove old etcd backups
|
|
|
|
shell:
|
|
|
|
chdir: "{{ etcd_backup_prefix }}"
|
2020-10-28 16:09:57 +00:00
|
|
|
cmd: "find . -name 'etcd-*' -type d | sort -n | head -n -{{ etcd_backup_retention_count }} | xargs rm -rf"
|
2020-10-23 14:09:57 +00:00
|
|
|
when: etcd_backup_retention_count >= 0
|