2018-09-29 09:06:19 +08:00
|
|
|
# cluster-backup playbook
|
|
|
|
# read the guide: 'op/cluster_restore.md'
|
2018-07-23 16:58:12 +08:00
|
|
|
|
|
|
|
- hosts:
|
|
|
|
- etcd
|
|
|
|
roles:
|
|
|
|
- cluster-backup
|
|
|
|
|
|
|
|
- hosts:
|
|
|
|
- deploy
|
|
|
|
tasks:
|
2018-09-29 09:06:19 +08:00
|
|
|
- name: Creating backup dirs
|
2018-07-23 16:58:12 +08:00
|
|
|
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"
|
|
|
|
|
2018-09-29 09:06:19 +08:00
|
|
|
- name: Backing up CA sth
|
2018-07-23 16:58:12 +08:00
|
|
|
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
|
|
|
|
|
2018-09-29 09:06:19 +08:00
|
|
|
- name: Backing up ansible hosts-1
|
2018-07-23 16:58:12 +08:00
|
|
|
copy:
|
|
|
|
src: "{{ base_dir }}/hosts"
|
|
|
|
dest: "{{ base_dir }}/roles/cluster-backup/files/hosts/hosts"
|
|
|
|
register: p
|
|
|
|
|
2018-09-29 09:06:19 +08:00
|
|
|
- name: Backing up ansible hosts-2
|
2018-07-23 16:58:12 +08:00
|
|
|
shell: "cd {{ base_dir }}/roles/cluster-backup/files/hosts && \
|
|
|
|
cp -fp hosts hosts-$(date +'%Y%m%d%H%M')"
|
2018-09-29 09:06:19 +08:00
|
|
|
when: 'p is changed'
|
2018-07-23 16:58:12 +08:00
|
|
|
|
2018-09-29 09:06:19 +08:00
|
|
|
- name: Backing up etcd snapshot-1
|
2018-07-23 16:58:12 +08:00
|
|
|
copy:
|
|
|
|
src: "{{ base_dir }}/roles/cluster-backup/files/snapshot.db"
|
|
|
|
dest: "{{ base_dir }}/roles/cluster-backup/files/snapshot/snapshot.db"
|
|
|
|
register: q
|
|
|
|
|
2018-09-29 09:06:19 +08:00
|
|
|
- name: Backing up etcd snapshot-2
|
2018-07-23 16:58:12 +08:00
|
|
|
shell: "cd {{ base_dir }}/roles/cluster-backup/files/ && \
|
|
|
|
mv -f snapshot.db snapshot/snapshot-$(date +'%Y%m%d%H%M').db"
|
2018-09-29 09:06:19 +08:00
|
|
|
when: 'q is changed'
|
2018-07-23 16:58:12 +08:00
|
|
|
|