-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backup/recovery: uncommenting and refactoring legacy code (#1241)
- Loading branch information
Showing
20 changed files
with
237 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
core/src/epicli/data/common/ansible/playbooks/backup_kubernetes.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
# Ansible playbook for backing up Kubernetes cluster | ||
|
||
- hosts: kubernetes_master[0] | ||
become: true | ||
become_method: sudo | ||
serial: 1 | ||
tasks: | ||
- import_role: | ||
name: backup | ||
tasks_from: kubernetes |
11 changes: 11 additions & 0 deletions
11
core/src/epicli/data/common/ansible/playbooks/backup_monitoring.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
# Ansible playbook for backing up monitoring data | ||
|
||
- hosts: prometheus | ||
become: true | ||
become_method: sudo | ||
serial: 1 | ||
tasks: | ||
- import_role: | ||
name: backup | ||
tasks_from: monitoring |
11 changes: 11 additions & 0 deletions
11
core/src/epicli/data/common/ansible/playbooks/backup_postgresql.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
# Ansible playbook for backing up Postgresql database | ||
|
||
- hosts: postgresql[0] | ||
become: true | ||
become_method: sudo | ||
serial: 1 | ||
tasks: | ||
- import_role: | ||
name: backup | ||
tasks_from: postgresql |
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
core/src/epicli/data/common/ansible/playbooks/recovery_kubernetes.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
# Ansible playbook for recovering Kubernetes cluster | ||
|
||
- hosts: kubernetes_master[0] | ||
become: true | ||
become_method: sudo | ||
serial: 1 | ||
tasks: | ||
- import_role: | ||
name: recovery | ||
tasks_from: kubernetes |
11 changes: 11 additions & 0 deletions
11
core/src/epicli/data/common/ansible/playbooks/recovery_monitoring.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
# Ansible playbook for recovering monitoring data | ||
|
||
- hosts: prometheus | ||
become: true | ||
become_method: sudo | ||
serial: 1 | ||
tasks: | ||
- import_role: | ||
name: recovery | ||
tasks_from: monitoring |
11 changes: 11 additions & 0 deletions
11
core/src/epicli/data/common/ansible/playbooks/recovery_postgresql.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
# Ansible playbook for recovering Postgresql database | ||
|
||
- hosts: postgresql[0] | ||
become: true | ||
become_method: sudo | ||
serial: 1 | ||
tasks: | ||
- import_role: | ||
name: recovery | ||
tasks_from: postgresql |
2 changes: 1 addition & 1 deletion
2
core/src/epicli/data/common/ansible/playbooks/roles/backup/defaults/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
--- | ||
backup_dir: /home/{{ admin_user.name }}/backupdir | ||
backup_dir: /epibackup |
3 changes: 0 additions & 3 deletions
3
core/src/epicli/data/common/ansible/playbooks/roles/backup/meta/main.yml
This file was deleted.
Oops, something went wrong.
104 changes: 104 additions & 0 deletions
104
core/src/epicli/data/common/ansible/playbooks/roles/backup/tasks/kubernetes.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
--- | ||
- name: Ensure backup directory exists | ||
file: | ||
path: "{{ backup_dir }}/" | ||
state: directory | ||
mode: u=rwx,go= | ||
|
||
- name: Create temporary directory | ||
tempfile: | ||
path: "{{ backup_dir }}/" | ||
suffix: .tmp | ||
state: directory | ||
register: backup_temp_dir | ||
|
||
- name: Save backup and cleanup afterwards | ||
always: | ||
- name: Delete temporary directory | ||
file: | ||
path: "{{ backup_temp_dir.path }}/" | ||
state: absent | ||
block: | ||
- name: Get etcd image name | ||
shell: | | ||
kubectl get pods \ | ||
--all-namespaces \ | ||
--output jsonpath={{ jsonpath }} | ||
vars: | ||
jsonpath: >- | ||
"{.items[*].spec.containers[?(@.name=='etcd')].image}" | ||
environment: | ||
KUBECONFIG: /etc/kubernetes/admin.conf | ||
register: etcd_image_name | ||
|
||
- name: Save etcd image name to a file | ||
copy: | ||
dest: "{{ backup_temp_dir.path }}/etcd_ver.txt" | ||
content: |- | ||
{{ etcd_image_name.stdout | trim }} | ||
- name: Save kubernetes PKI | ||
copy: | ||
src: /etc/kubernetes/pki # do not put / at the end here! | ||
dest: "{{ backup_temp_dir.path }}/" | ||
remote_src: true | ||
|
||
- name: Save etcd snapshot | ||
shell: | | ||
docker run \ | ||
-v "{{ backup_temp_dir.path }}/:/backup/" \ | ||
--network host \ | ||
--env ETCDCTL_API=3 \ | ||
--rm "{{ etcd_image_name.stdout | trim }}" \ | ||
etcdctl \ | ||
--endpoints https://127.0.0.1:2379 \ | ||
--cacert /backup/pki/etcd/ca.crt \ | ||
--cert /backup/pki/etcd/healthcheck-client.crt \ | ||
--key /backup/pki/etcd/healthcheck-client.key \ | ||
snapshot save /backup/etcd-snapshot.db | ||
args: | ||
executable: /bin/bash | ||
|
||
- name: Check if kubeadm configuration file exists | ||
stat: | ||
path: /etc/kubeadm/kubeadm-config.yml | ||
get_attributes: false | ||
get_checksum: false | ||
get_mime: false | ||
register: stat_kubeadm_config_yml | ||
|
||
- when: stat_kubeadm_config_yml.stat.exists | ||
block: | ||
- name: Save kubeadm configuration file | ||
copy: | ||
src: "{{ stat_kubeadm_config_yml.stat.path }}" | ||
dest: "{{ backup_temp_dir.path }}/" | ||
remote_src: true | ||
|
||
- name: Get current timestamp | ||
run_once: true | ||
set_fact: | ||
timestamp: "{{ ansible_date_time.iso8601_basic_short }}" | ||
|
||
- name: Create tar.gz archive | ||
archive: | ||
path: "{{ backup_temp_dir.path }}/" | ||
dest: "{{ backup_dir }}/k8s_backup_{{ timestamp }}.tar.gz" | ||
format: gz | ||
|
||
- name: Create checksum file | ||
block: | ||
- name: Calculate checksum | ||
stat: | ||
path: "{{ backup_dir }}/k8s_backup_{{ timestamp }}.tar.gz" | ||
get_attributes: false | ||
get_checksum: true | ||
get_mime: false | ||
checksum_algorithm: sha1 | ||
register: stat_k8s_backup_tar_gz | ||
|
||
- name: Save checksum to a file | ||
copy: | ||
dest: "{{ stat_k8s_backup_tar_gz.stat.path }}.sha1" | ||
content: | | ||
{{ stat_k8s_backup_tar_gz.stat.checksum }} {{ stat_k8s_backup_tar_gz.stat.path | basename }} |
Oops, something went wrong.