Skip to content

Commit

Permalink
New dev (#1193)
Browse files Browse the repository at this point in the history
优化etcd 恢复逻辑
  • Loading branch information
itswl authored and gjmzj committed Jan 7, 2023
1 parent 5a01a25 commit 807d712
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions roles/cluster-restore/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,20 @@
- name: 清除etcd 数据目录
file: name={{ ETCD_DATA_DIR }}/member state=absent

- name: 生成备份目录
file: name=/etcd_backup state=directory

- name: 准备指定的备份etcd 数据
copy:
src: "{{ cluster_dir }}/backup/{{ db_to_restore }}"
dest: "/etcd_backup/snapshot.db"

- name: 清理上次备份恢复数据
file: name=/etcd_backup/etcd-{{ inventory_hostname }}.etcd state=absent
- name: 清除 etcd 备份目录
file: name={{ cluster_dir }}/backup/etcd-restore state=absent
delegate_to: 127.0.0.1
run_once: true

- name: etcd 数据恢复
shell: "cd /etcd_backup && \
ETCDCTL_API=3 {{ bin_dir }}/etcdctl snapshot restore snapshot.db \
--name etcd-{{ inventory_hostname }} \
--initial-cluster {{ ETCD_NODES }} \
--initial-cluster-token etcd-cluster-0 \
--initial-advertise-peer-urls https://{{ inventory_hostname }}:2380"

- name: 恢复数据至etcd 数据目录
shell: "cp -rf /etcd_backup/etcd-{{ inventory_hostname }}.etcd/member {{ ETCD_DATA_DIR }}/"
shell: "cd {{ cluster_dir }}/backup && \
ETCDCTL_API=3 {{ base_dir }}/bin/etcdctl snapshot restore snapshot.db \
--data-dir={{ cluster_dir }}/backup/etcd-restore"
delegate_to: 127.0.0.1
run_once: true

- name: 分发恢复文件到 etcd 各个节点
copy: src={{ cluster_dir }}/backup/etcd-restore/member dest={{ ETCD_DATA_DIR }}

- name: 重启etcd 服务
service: name=etcd state=restarted
Expand Down

0 comments on commit 807d712

Please sign in to comment.