mirror of https://github.com/easzlab/kubeasz.git
增加集群备份功能
parent
37452f956f
commit
df8faebd86
|
@ -6,5 +6,5 @@ bin/*
|
|||
manifests/kubedns/kubedns.yaml
|
||||
manifests/coredns/coredns.yaml
|
||||
hosts
|
||||
*.crt
|
||||
*.pem
|
||||
roles/cluster-backup/files/*
|
||||
!roles/cluster-backup/files/readme.md
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
# 集群备份脚本,请详细参阅文档 docs/op/cluster_restore.md
|
||||
|
||||
- hosts:
|
||||
- etcd
|
||||
roles:
|
||||
- cluster-backup
|
||||
|
||||
- hosts:
|
||||
- deploy
|
||||
tasks:
|
||||
- name: 准备备份目录
|
||||
file: name={{ item }} state=directory
|
||||
with_items:
|
||||
- "{{ base_dir }}/roles/cluster-backup/files/ca"
|
||||
- "{{ base_dir }}/roles/cluster-backup/files/hosts"
|
||||
- "{{ base_dir }}/roles/cluster-backup/files/snapshot"
|
||||
|
||||
- name: 备份 CA 相关文件
|
||||
copy:
|
||||
src: "{{ ca_dir }}/{{ item }}"
|
||||
dest: "{{ base_dir }}/roles/cluster-backup/files/ca/{{ item }}"
|
||||
with_items:
|
||||
- ca.pem
|
||||
- ca-key.pem
|
||||
- ca.csr
|
||||
- ca-csr.json
|
||||
- ca-config.json
|
||||
|
||||
- name: 备份 ansible hosts 1
|
||||
copy:
|
||||
src: "{{ base_dir }}/hosts"
|
||||
dest: "{{ base_dir }}/roles/cluster-backup/files/hosts/hosts"
|
||||
register: p
|
||||
|
||||
- name: 备份 ansible hosts 2
|
||||
shell: "cd {{ base_dir }}/roles/cluster-backup/files/hosts && \
|
||||
cp -fp hosts hosts-$(date +'%Y%m%d%H%M')"
|
||||
when: p | changed
|
||||
|
||||
- name: 备份 etcd snapshot 1
|
||||
copy:
|
||||
src: "{{ base_dir }}/roles/cluster-backup/files/snapshot.db"
|
||||
dest: "{{ base_dir }}/roles/cluster-backup/files/snapshot/snapshot.db"
|
||||
register: q
|
||||
|
||||
- name: 备份 etcd snapshot 2
|
||||
shell: "cd {{ base_dir }}/roles/cluster-backup/files/ && \
|
||||
mv -f snapshot.db snapshot/snapshot-$(date +'%Y%m%d%H%M').db"
|
||||
when: q | changed
|
||||
|
|
@ -135,6 +135,7 @@
|
|||
with_items:
|
||||
- "/var/lib/etcd"
|
||||
- "/etc/etcd/"
|
||||
- "/backup/k8s"
|
||||
- "/etc/systemd/system/etcd.service"
|
||||
|
||||
# 清理负载均衡相关
|
||||
|
|
|
@ -14,7 +14,7 @@ $ ETCDCTL_API=3 etcdctl snapshot save backup.db
|
|||
# 查看备份
|
||||
$ ETCDCTL_API=3 etcdctl --write-out=table snapshot status backup.db
|
||||
```
|
||||
- 从备份恢复可以参考[官方说明](https://github.com/coreos/etcd/blob/master/Documentation/op-guide/recovery.md)
|
||||
- 从备份恢复可以参考:[备份恢复](cluster_restore.md)
|
||||
|
||||
### 升级步骤
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
# 集群备份目录
|
||||
|
||||
此目标保留作为k8s 集群备份使用。
|
|
@ -0,0 +1,14 @@
|
|||
- name: 准备备份目录
|
||||
file: name=/backup/k8s state=directory
|
||||
|
||||
- name: 执行etcd 数据备份
|
||||
shell: "cd /backup/k8s && \
|
||||
ETCDCTL_API=3 {{ bin_dir }}/etcdctl snapshot save snapshot.db"
|
||||
|
||||
- name: 获取etcd 数据备份
|
||||
fetch:
|
||||
src: /backup/k8s/snapshot.db
|
||||
dest: /etc/ansible/roles/cluster-backup/files/
|
||||
flat: yes
|
||||
run_once: true
|
||||
|
Loading…
Reference in New Issue