-
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: logging (WIP) (#1277)
- work in progress, does not work with elasticsearch clusters yet
- Loading branch information
Showing
14 changed files
with
558 additions
and
5 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
29 changes: 29 additions & 0 deletions
29
core/src/epicli/data/common/ansible/playbooks/backup_logging.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,29 @@ | ||
--- | ||
# Ansible playbook for backing up logging data | ||
|
||
- hosts: logging[0] | ||
gather_facts: true | ||
become: true | ||
become_method: sudo | ||
serial: 1 | ||
tasks: | ||
- import_role: | ||
name: backup | ||
tasks_from: logging_elasticsearch_snapshot | ||
- import_role: | ||
name: backup | ||
tasks_from: logging_elasticsearch_etc | ||
vars_files: | ||
- roles/logging/vars/main.yml | ||
|
||
- hosts: kibana[0] | ||
gather_facts: true | ||
become: true | ||
become_method: sudo | ||
serial: 1 | ||
tasks: | ||
- import_role: | ||
name: backup | ||
tasks_from: logging_kibana_etc | ||
vars_files: | ||
- roles/kibana/vars/main.yml |
28 changes: 28 additions & 0 deletions
28
core/src/epicli/data/common/ansible/playbooks/recovery_logging.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,28 @@ | ||
--- | ||
# Ansible playbook for recovering logging data | ||
|
||
- hosts: logging[0] | ||
become: true | ||
become_method: sudo | ||
serial: 1 | ||
tasks: | ||
- import_role: | ||
name: recovery | ||
tasks_from: logging_elasticsearch_etc | ||
- import_role: | ||
name: recovery | ||
tasks_from: logging_elasticsearch_snapshot | ||
vars_files: | ||
- roles/logging/vars/main.yml | ||
|
||
- hosts: kibana[0] | ||
gather_facts: true | ||
become: true | ||
become_method: sudo | ||
serial: 1 | ||
tasks: | ||
- import_role: | ||
name: recovery | ||
tasks_from: logging_kibana_etc | ||
vars_files: | ||
- roles/kibana/vars/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
52 changes: 52 additions & 0 deletions
52
...src/epicli/data/common/ansible/playbooks/roles/backup/tasks/logging_elasticsearch_etc.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,52 @@ | ||
--- | ||
- name: Assert that the "snapshot_name" fact is defined and valid | ||
assert: | ||
that: | ||
- snapshot_name is defined | ||
- snapshot_name is string | ||
- snapshot_name | length > 0 | ||
fail_msg: The "snapshot_name" fact must be defined and must be a non-empty string. | ||
|
||
- name: Create and copy etc archive to backup destination | ||
always: | ||
- name: Delete etc archive (cleanup) | ||
file: | ||
path: "{{ item }}" | ||
state: absent | ||
loop: | ||
- "{{ backup_dir }}/elasticsearch_etc_{{ snapshot_name }}.tar.gz" | ||
- "{{ backup_dir }}/elasticsearch_etc_{{ snapshot_name }}.tar.gz.sha1" | ||
|
||
block: | ||
- name: Ensure backup dir exists | ||
file: | ||
path: "{{ backup_dir }}/" | ||
state: directory | ||
|
||
- name: Create etc archive | ||
archive: | ||
dest: "{{ backup_dir }}/elasticsearch_etc_{{ snapshot_name }}.tar.gz" | ||
path: /etc/elasticsearch/ # keep the / here! | ||
format: gz | ||
|
||
- name: Calculate checksum from etc archive | ||
stat: | ||
path: "{{ backup_dir }}/elasticsearch_etc_{{ snapshot_name }}.tar.gz" | ||
get_attributes: false | ||
get_checksum: true | ||
get_mime: false | ||
checksum_algorithm: sha1 | ||
register: stat_elasticsearch_etc_archive | ||
|
||
- name: Store etc archive checksum in a file | ||
copy: | ||
dest: "{{ backup_dir }}/elasticsearch_etc_{{ snapshot_name }}.tar.gz.sha1" | ||
content: | | ||
{{ stat_elasticsearch_etc_archive.stat.checksum }} elasticsearch_etc_{{ snapshot_name }}.tar.gz | ||
- name: Transfer etc archive via rsync | ||
import_tasks: download_via_rsync.yml | ||
vars: | ||
artifacts: | ||
- "{{ backup_dir }}/elasticsearch_etc_{{ snapshot_name }}.tar.gz" | ||
- "{{ backup_dir }}/elasticsearch_etc_{{ snapshot_name }}.tar.gz.sha1" |
111 changes: 111 additions & 0 deletions
111
...picli/data/common/ansible/playbooks/roles/backup/tasks/logging_elasticsearch_snapshot.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,111 @@ | ||
--- | ||
- name: Set helper facts | ||
set_fact: | ||
elasticsearch_endpoint: >- | ||
https://{{ ansible_default_ipv4.address }}:9200 | ||
snapshot_name: >- | ||
{{ ansible_date_time.iso8601_basic_short | replace('T','-') }} | ||
vars: | ||
uri_template: &uri | ||
client_cert: /etc/elasticsearch/kirk.pem | ||
client_key: /etc/elasticsearch/kirk-key.pem | ||
validate_certs: false | ||
body_format: json | ||
|
||
- debug: var=snapshot_name | ||
|
||
- name: Check cluster health | ||
uri: | ||
<<: *uri | ||
url: "{{ elasticsearch_endpoint }}/_cluster/health" | ||
method: GET | ||
register: uri_response | ||
until: uri_response is success | ||
retries: 12 | ||
delay: 5 | ||
|
||
- name: Ensure snapshot repository is defined | ||
uri: | ||
<<: *uri | ||
url: "{{ elasticsearch_endpoint }}/_snapshot/{{ elasticsearch_snapshot_repository_name }}" | ||
method: PUT | ||
body: | ||
type: fs | ||
settings: | ||
location: "{{ elasticsearch_snapshot_repository_location }}" | ||
compress: true | ||
|
||
- name: Trigger snapshot creation | ||
uri: | ||
<<: *uri | ||
url: "{{ elasticsearch_endpoint }}/_snapshot/{{ elasticsearch_snapshot_repository_name }}/{{ snapshot_name }}" | ||
method: PUT | ||
|
||
- name: Wait (up to 12h) for snapshot completion | ||
uri: | ||
<<: *uri | ||
url: "{{ elasticsearch_endpoint }}/_snapshot/{{ elasticsearch_snapshot_repository_name }}/{{ snapshot_name }}" | ||
method: GET | ||
register: uri_response | ||
until: (uri_response.json.snapshots | selectattr('snapshot', 'equalto', snapshot_name) | first).state == "SUCCESS" | ||
retries: "{{ (12 * 3600 // 10) | int }}" # 12h | ||
delay: 10 | ||
|
||
- name: Find all snapshots | ||
uri: | ||
<<: *uri | ||
url: "{{ elasticsearch_endpoint }}/_snapshot/{{ elasticsearch_snapshot_repository_name }}/_all" | ||
method: GET | ||
register: uri_response | ||
|
||
- name: Delete old snapshots | ||
uri: | ||
<<: *uri | ||
url: "{{ elasticsearch_endpoint }}/_snapshot/{{ elasticsearch_snapshot_repository_name }}/{{ item }}" | ||
method: DELETE | ||
loop: >- | ||
{{ uri_response.json.snapshots | map(attribute='snapshot') | reject('equalto', snapshot_name) | list }} | ||
- name: Create and copy snapshot archive to backup destination | ||
always: | ||
- name: Delete snapshot archive (cleanup) | ||
file: | ||
path: "{{ item }}" | ||
state: absent | ||
loop: | ||
- "{{ backup_dir }}/elasticsearch_snapshot_{{ snapshot_name }}.tar.gz" | ||
- "{{ backup_dir }}/elasticsearch_snapshot_{{ snapshot_name }}.tar.gz.sha1" | ||
|
||
block: | ||
- name: Ensure backup dir exists | ||
file: | ||
path: "{{ backup_dir }}/" | ||
state: directory | ||
|
||
- name: Create snapshot archive | ||
archive: | ||
dest: "{{ backup_dir }}/elasticsearch_snapshot_{{ snapshot_name }}.tar.gz" | ||
path: "{{ elasticsearch_snapshot_repository_location }}/*" | ||
format: gz | ||
|
||
- name: Calculate checksum from snapshot archive | ||
stat: | ||
path: "{{ backup_dir }}/elasticsearch_snapshot_{{ snapshot_name }}.tar.gz" | ||
get_attributes: false | ||
get_checksum: true | ||
get_mime: false | ||
checksum_algorithm: sha1 | ||
register: stat_snapshot_archive | ||
|
||
- name: Store snapshot archive checksum in a file | ||
copy: | ||
dest: "{{ backup_dir }}/elasticsearch_snapshot_{{ snapshot_name }}.tar.gz.sha1" | ||
content: | | ||
{{ stat_snapshot_archive.stat.checksum }} elasticsearch_snapshot_{{ snapshot_name }}.tar.gz | ||
- name: Transfer snapshot archive via rsync | ||
import_tasks: download_via_rsync.yml | ||
vars: | ||
artifacts: | ||
- "{{ backup_dir }}/elasticsearch_snapshot_{{ snapshot_name }}.tar.gz" | ||
- "{{ backup_dir }}/elasticsearch_snapshot_{{ snapshot_name }}.tar.gz.sha1" |
52 changes: 52 additions & 0 deletions
52
core/src/epicli/data/common/ansible/playbooks/roles/backup/tasks/logging_kibana_etc.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,52 @@ | ||
--- | ||
- name: Assert that the "snapshot_name" fact is defined and valid | ||
assert: | ||
that: | ||
- snapshot_name is defined | ||
- snapshot_name is string | ||
- snapshot_name | length > 0 | ||
fail_msg: The "snapshot_name" fact must be defined and must be a non-empty string. | ||
|
||
- name: Create and copy etc archive to backup destination | ||
always: | ||
- name: Delete etc archive (cleanup) | ||
file: | ||
path: "{{ item }}" | ||
state: absent | ||
loop: | ||
- "{{ backup_dir }}/kibana_etc_{{ snapshot_name }}.tar.gz" | ||
- "{{ backup_dir }}/kibana_etc_{{ snapshot_name }}.tar.gz.sha1" | ||
|
||
block: | ||
- name: Ensure backup dir exists | ||
file: | ||
path: "{{ backup_dir }}/" | ||
state: directory | ||
|
||
- name: Create etc archive | ||
archive: | ||
dest: "{{ backup_dir }}/kibana_etc_{{ snapshot_name }}.tar.gz" | ||
path: /etc/kibana/ # keep the / here! | ||
format: gz | ||
|
||
- name: Calculate checksum from etc archive | ||
stat: | ||
path: "{{ backup_dir }}/kibana_etc_{{ snapshot_name }}.tar.gz" | ||
get_attributes: false | ||
get_checksum: true | ||
get_mime: false | ||
checksum_algorithm: sha1 | ||
register: stat_etc_archive | ||
|
||
- name: Store etc archive checksum in a file | ||
copy: | ||
dest: "{{ backup_dir }}/kibana_etc_{{ snapshot_name }}.tar.gz.sha1" | ||
content: | | ||
{{ stat_etc_archive.stat.checksum }} kibana_etc_{{ snapshot_name }}.tar.gz | ||
- name: Transfer etc archive via rsync | ||
import_tasks: download_via_rsync.yml | ||
vars: | ||
artifacts: | ||
- "{{ backup_dir }}/kibana_etc_{{ snapshot_name }}.tar.gz" | ||
- "{{ backup_dir }}/kibana_etc_{{ snapshot_name }}.tar.gz.sha1" |
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 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
Oops, something went wrong.