kubeasz/roles/cluster-restore/tasks/main.yml

38 lines
1.1 KiB
YAML
Raw Normal View History

2018-07-23 16:59:44 +08:00
- name: 停止ectd 服务
service: name=etcd state=stopped
- name: 清除etcd 数据目录
file: name=/var/lib/etcd/member state=absent
- name: 生成备份目录
file: name=/etcd_backup state=directory
2018-07-23 16:59:44 +08:00
- name: 准备指定的备份etcd 数据
copy:
2020-12-25 11:53:00 +08:00
src: "{{ cluster_dir }}/backup/{{ db_to_restore }}"
dest: "/etcd_backup/snapshot.db"
2018-07-23 16:59:44 +08:00
- name: 清理上次备份恢复数据
2021-01-07 09:30:50 +08:00
file: name=/etcd_backup/etcd-{{ inventory_hostname }}.etcd state=absent
2018-07-23 16:59:44 +08:00
- name: etcd 数据恢复
shell: "cd /etcd_backup && \
2018-07-23 16:59:44 +08:00
ETCDCTL_API=3 {{ bin_dir }}/etcdctl snapshot restore snapshot.db \
2021-01-07 09:30:50 +08:00
--name etcd-{{ inventory_hostname }} \
2018-07-23 16:59:44 +08:00
--initial-cluster {{ ETCD_NODES }} \
--initial-cluster-token etcd-cluster-0 \
--initial-advertise-peer-urls https://{{ inventory_hostname }}:2380"
- name: 恢复数据至etcd 数据目录
2021-01-07 09:30:50 +08:00
shell: "cp -rf /etcd_backup/etcd-{{ inventory_hostname }}.etcd/member /var/lib/etcd/"
2018-07-23 16:59:44 +08:00
- name: 重启etcd 服务
service: name=etcd state=restarted
2021-01-07 09:30:50 +08:00
- name: 以轮询的方式等待服务同步完成
shell: "systemctl status etcd.service|grep Active"
register: etcd_status
until: '"running" in etcd_status.stdout'
retries: 8
delay: 8