2017-03-17 03:38:13 +08:00
|
|
|
---
|
|
|
|
- name: Refresh Time Fact
|
2023-06-26 18:15:45 +08:00
|
|
|
setup:
|
|
|
|
filter: ansible_date_time
|
2023-11-08 19:28:30 +08:00
|
|
|
listen: Restart etcd
|
|
|
|
when: etcd_cluster_is_healthy.rc == 0
|
2017-03-17 03:38:13 +08:00
|
|
|
|
|
|
|
- name: Set Backup Directory
|
|
|
|
set_fact:
|
|
|
|
etcd_backup_directory: "{{ etcd_backup_prefix }}/etcd-{{ ansible_date_time.date }}_{{ ansible_date_time.time }}"
|
2023-11-08 19:28:30 +08:00
|
|
|
listen: Restart etcd
|
2017-03-17 03:38:13 +08:00
|
|
|
|
|
|
|
- name: Create Backup Directory
|
|
|
|
file:
|
|
|
|
path: "{{ etcd_backup_directory }}"
|
|
|
|
state: directory
|
|
|
|
owner: root
|
|
|
|
group: root
|
2024-07-26 09:42:20 +08:00
|
|
|
mode: "0600"
|
2023-11-08 19:28:30 +08:00
|
|
|
listen: Restart etcd
|
|
|
|
when: etcd_cluster_is_healthy.rc == 0
|
2017-03-17 03:38:13 +08:00
|
|
|
|
2017-08-31 23:23:24 +08:00
|
|
|
- name: Stat etcd v2 data directory
|
|
|
|
stat:
|
|
|
|
path: "{{ etcd_data_dir }}/member"
|
2024-08-28 13:30:56 +08:00
|
|
|
get_attributes: false
|
|
|
|
get_checksum: false
|
|
|
|
get_mime: false
|
2017-08-31 23:23:24 +08:00
|
|
|
register: etcd_data_dir_member
|
2023-11-08 19:28:30 +08:00
|
|
|
listen: Restart etcd
|
|
|
|
when: etcd_cluster_is_healthy.rc == 0
|
2017-08-31 23:23:24 +08:00
|
|
|
|
2017-03-17 03:38:13 +08:00
|
|
|
- name: Backup etcd v2 data
|
2023-11-08 19:28:30 +08:00
|
|
|
when:
|
|
|
|
- etcd_data_dir_member.stat.exists
|
|
|
|
- etcd_cluster_is_healthy.rc == 0
|
2017-03-24 00:56:30 +08:00
|
|
|
command: >-
|
|
|
|
{{ bin_dir }}/etcdctl backup
|
|
|
|
--data-dir {{ etcd_data_dir }}
|
|
|
|
--backup-dir {{ etcd_backup_directory }}
|
2017-03-17 03:38:13 +08:00
|
|
|
environment:
|
2023-06-26 18:15:45 +08:00
|
|
|
ETCDCTL_API: "2"
|
2017-03-17 03:38:13 +08:00
|
|
|
retries: 3
|
2018-08-17 17:05:57 +08:00
|
|
|
register: backup_v2_command
|
|
|
|
until: backup_v2_command.rc == 0
|
2017-03-17 03:38:13 +08:00
|
|
|
delay: "{{ retry_stagger | random + 3 }}"
|
2023-11-08 19:28:30 +08:00
|
|
|
listen: Restart etcd
|
2017-03-17 03:38:13 +08:00
|
|
|
|
|
|
|
- name: Backup etcd v3 data
|
2017-03-24 00:56:30 +08:00
|
|
|
command: >-
|
|
|
|
{{ bin_dir }}/etcdctl
|
|
|
|
snapshot save {{ etcd_backup_directory }}/snapshot.db
|
2017-03-17 03:38:13 +08:00
|
|
|
environment:
|
2023-06-26 18:15:45 +08:00
|
|
|
ETCDCTL_API: "3"
|
2020-07-20 22:26:51 +08:00
|
|
|
ETCDCTL_ENDPOINTS: "{{ etcd_access_addresses.split(',') | first }}"
|
2018-04-01 02:06:09 +08:00
|
|
|
ETCDCTL_CERT: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
|
|
|
|
ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
|
2019-03-28 15:18:43 +08:00
|
|
|
ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem"
|
2017-03-17 03:38:13 +08:00
|
|
|
retries: 3
|
2018-08-17 17:05:57 +08:00
|
|
|
register: etcd_backup_v3_command
|
|
|
|
until: etcd_backup_v3_command.rc == 0
|
2017-03-17 03:38:13 +08:00
|
|
|
delay: "{{ retry_stagger | random + 3 }}"
|
2023-11-08 19:28:30 +08:00
|
|
|
listen: Restart etcd
|
|
|
|
when: etcd_cluster_is_healthy.rc == 0
|