Skip to content

Commit

Permalink
Fix backup and recovery for logging (#3255)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasz-baran authored Aug 11, 2022
1 parent 67a418c commit cbb930b
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 46 deletions.
28 changes: 17 additions & 11 deletions ansible/playbooks/backup_logging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,28 @@
include_vars:
file: roles/logging/vars/main.yml
name: component_vars

- name: Run elasticsearch snapshot tasks
import_role:
name: backup
tasks_from: logging_opensearch_snapshot

- name: Run elasticsearch archive tasks
import_role:
name: backup
tasks_from: logging_opensearch_conf
# OpenSearch Dashboards
- name: Include opensearch_dashboards vars
include_vars:
file: roles/opensearch_dashboards/vars/main.yml
name: component_vars
- name: Run opensearch_dashboards backup tasks
import_role:
name: backup
tasks_from: logging_opensearch_dashboards_conf
vars:
snapshot_name: "{{ hostvars[groups.logging.0].snapshot_name }}"

- name: OpenSearch Dashboards
when: "'opensearch_dashboards' in group_names"
block:
- name: Include opensearch_dashboards vars
include_vars:
file: roles/opensearch_dashboards/vars/main.yml
name: component_vars

- name: Run opensearch_dashboards backup tasks
import_role:
name: backup
tasks_from: logging_opensearch_dashboards_conf
vars:
snapshot_name: "{{ hostvars[groups.logging.0].snapshot_name }}"
19 changes: 12 additions & 7 deletions ansible/playbooks/recovery_logging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@
- include_vars:
file: roles/logging/vars/main.yml
name: component_vars

- import_role:
name: recovery
tasks_from: logging_opensearch_conf

- import_role:
name: recovery
tasks_from: logging_opensearch_snapshot

# OpenSearch Dashboards
- include_vars:
file: roles/opensearch_dashboards/vars/main.yml
name: component_vars
- import_role:
name: recovery
tasks_from: logging_opensearch_dashboards_conf
- name: OpenSearch Dashboards
when: "'opensearch_dashboards' in group_names"
block:
- include_vars:
file: roles/opensearch_dashboards/vars/main.yml
name: component_vars

- import_role:
name: recovery
tasks_from: logging_opensearch_dashboards_conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
file: roles/opensearch/defaults/main.yml
name: opensearch_defaults

- name: Include vars from opensearch role
include_vars:
file: roles/opensearch/vars/main.yml
name: opensearch_vars

- name: Assert that the snapshot_name fact is defined and valid
assert:
that:
Expand All @@ -23,9 +18,9 @@
- name: Create snapshot archive
import_tasks: common/create_snapshot_archive.yml
vars:
snapshot_prefix: "opensearch_conf"
snapshot_prefix: logging_opensearch_conf
dirs_to_archive:
- "{{ opensearch_vars.specification.paths.opensearch_conf_dir }}"
- "{{ component_vars.specification.paths.opensearch_conf_dir }}"

- name: Create snapshot checksum
import_tasks: common/create_snapshot_checksum.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
- name: Create snapshot archive
import_tasks: common/create_snapshot_archive.yml
vars:
snapshot_prefix: "opensearch_dashboards_conf_dir"
snapshot_prefix: logging_opensearch_dashboards_conf
dirs_to_archive:
- "{{ opensearch_dashboards_vars.specification.paths.opensearch_dashboards_conf_dir }}"
- "{{ opensearch_dashboards_vars.specification.paths.dashboards_conf_dir }}"

- name: Create snapshot checksum
import_tasks: common/create_snapshot_checksum.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
- name: Create snapshot archive
import_tasks: common/create_snapshot_archive.yml
vars:
snapshot_prefix: "opensearch_snapshot"
snapshot_prefix: logging_opensearch_snapshot
dirs_to_archive:
- "{{ opensearch_snapshot_repository_location }}/"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
---
- name: Include vars from opensearch role
include_vars:
file: roles/opensearch/vars/main.yml
name: opensearch_vars

- name: Find snapshot archive
import_tasks: common/find_snapshot_archive.yml
vars:
snapshot_prefix: "opensearch_conf"
snapshot_prefix: logging_opensearch_conf
snapshot_name: "{{ specification.components.logging.snapshot_name }}"

- name: Transfer the archive via rsync
Expand All @@ -29,11 +24,11 @@
import_tasks: common/clear_directories.yml
vars:
dirs_to_clear:
- "{{ opensearch_vars.specification.paths.opensearch_conf_dir }}"
- "{{ component_vars.specification.paths.opensearch_conf_dir }}"

- name: Extract the archive
unarchive:
dest: "{{ opensearch_vars.specification.paths.opensearch_conf_dir }}"
dest: "{{ component_vars.specification.paths.opensearch_conf_dir }}"
src: "{{ recovery_dir }}/{{ snapshot_path | basename }}"
remote_src: true

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
- name: Include vars from opensearch role
- name: Include vars from opensearch_dashboards role
include_vars:
file: roles/opensearch_dashboards/vars/main.yml
name: opensearch_dashboards_vars

- name: Find snapshot archive
import_tasks: common/find_snapshot_archive.yml
vars:
snapshot_prefix: "opsd_conf_dir"
snapshot_prefix: logging_opensearch_dashboards_conf
snapshot_name: "{{ specification.components.logging.snapshot_name }}"

- name: Transfer the archive via rsync
Expand All @@ -29,11 +29,11 @@
import_tasks: common/clear_directories.yml
vars:
dirs_to_clear:
- "{{ opensearch_dashboards_vars.specification.paths.opsd_conf_dir }}"
- "{{ opensearch_dashboards_vars.specification.paths.dashboards_conf_dir }}"

- name: Extract the archive
unarchive:
dest: "{{ opensearch_dashboards_vars.specification.paths.opsd_conf_dir }}"
dest: "{{ opensearch_dashboards_vars.specification.paths.dashboards_conf_dir }}"
src: "{{ recovery_dir }}/{{ snapshot_path | basename }}"
remote_src: true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
- name: Include default vars from opensearch role
include_vars:
file: roles/opensearch/defaults/main.yml
name: odfe
name: opensearch_defaults

- name: Set helper facts
set_fact:
opensearch_endpoint: >-
https://{{ ansible_default_ipv4.address }}:9200
vars:
uri_template: &uri
client_cert: "{{ odfe.certificates.dirs.certs }}/{{ odfe.certificates.files.admin.cert.filename }}"
client_key: "{{ odfe.certificates.dirs.certs }}/{{ odfe.certificates.files.admin.key.filename }}"
client_cert: "{{ opensearch_defaults.certificates.dirs.certs }}/{{ opensearch_defaults.certificates.files.admin.cert.filename }}"
client_key: "{{ opensearch_defaults.certificates.dirs.certs }}/{{ opensearch_defaults.certificates.files.admin.key.filename }}"
validate_certs: false
body_format: json

Expand All @@ -28,7 +28,7 @@
- name: Find snapshot archive
import_tasks: common/find_snapshot_archive.yml
vars:
snapshot_prefix: "opensearch_snapshot"
snapshot_prefix: logging_opensearch_snapshot
snapshot_name: "{{ specification.components.logging.snapshot_name }}"

- name: Transfer the archive via rsync
Expand Down Expand Up @@ -63,14 +63,14 @@
- name: Reconstruct the snapshot_name
set_fact:
snapshot_name: >-
{{ snapshot_path | basename | regex_replace('^opensearch_snapshot_(.*).tar.gz$', '\1') }}
{{ snapshot_path | basename | regex_replace('^logging_opensearch_snapshot_(.*).tar.gz$', '\1') }}
- name: Display snapshot name
debug: var=snapshot_name

- name: Ensure all OPSD and filebeat instances are stopped, then restore the snapshot
block:
- name: Stop allOpenSearch Dashboards instances
- name: Stop all OpenSearch Dashboards instances
delegate_to: "{{ item }}"
systemd:
name: opensearch-dashboards
Expand Down

0 comments on commit cbb930b

Please sign in to comment.