Commit 60226ec2 authored by Jürgen Haas's avatar Jürgen Haas

customer/bitegra/portal/support#1 Implement elasticsearch backup

parent 61f91f0d
#!/bin/bash
if [[ "x$1" = "x" ]]; then
DATE=`date +%Y.%m.%d`
elasticsearch-remove-readonly .kibana_2
elasticsearch-remove-readonly .kibana_1
elasticsearch-remove-readonly ansible
elasticsearch-remove-readonly uptime
elasticsearch-remove-readonly logstash-$DATE
elasticsearch-remove-readonly heartbeat-6.6.1-$DATE
exit 0
fi
echo ""
echo "Unlock $1"
curl -X PUT http://127.0.0.1:9200/$1/_settings -H 'Content-Type: application/json' -d '{"index.blocks.read_only_allow_delete":null}'
---
# file: roles/elasticsearch/tasks/backup.yml
- name: Register snapshot repository
uri:
url: http://localhost:9200/_snapshot/Backup
method: PUT
user: elastic
password: '{{ elasticsearch.users.elastic|default("") }}'
body: '{"type":"source","settings":{"delegate_type":"fs","location":"/var/backups/elasticsearch"}}'
force_basic_auth: yes
status_code: 200
body_format: json
- name: Copy snapshot script
template:
src: elasticsearch-snapshot
dest: /usr/local/bin/elasticsearch-snapshot
mode: 0755
- name: Backup Cron
cron:
name: Elasticsearch backup
hour: 2
job: /usr/local/bin/elasticsearch-snapshot >/dev/null 2>&1
......@@ -50,6 +50,15 @@
line: 'xpack.security.enabled: true'
- regexp: 'xpack.security.transport.ssl.enabled'
line: 'xpack.security.transport.ssl.enabled: false'
- regexp: 'path.repo'
line: 'path.repo: ["/var/backups/elasticsearch"]'
- name: Prepare backup directory
file:
path: /var/backups/elasticsearch
state: directory
owner: elasticsearch
group: elasticsearch
- name: Start Elasticsearch
service:
......
......@@ -27,4 +27,8 @@
- name: Import readonly
import_tasks: readonly.yml
- name: Include backup
include_tasks: backup.yml
when: elasticsearch.snapshot is defined and elasticsearch.snapshot.indices is defined
when: not excluded_roles or "elasticsearch" not in excluded_roles
......@@ -2,7 +2,7 @@
# file: roles/elasticsearch/tasks/readonly.yml
- name: Copy script
copy:
template:
src: elasticsearch-remove-readonly
dest: /usr/local/bin/elasticsearch-remove-readonly
mode: 0755
......
#!/bin/bash
curl -X PUT http://elastic:{{ elasticsearch.users.elastic|default('') }}@localhost:9200/_all/_settings -H 'Content-Type: application/json' -d'{ "index.blocks.read_only_allow_delete" : false } }'
#!/bin/bash
{% set ES_INDICES = elasticsearch.snapshot.indices|join(',') %}
curl -X PUT 'http://elastic:{{ elasticsearch.users.elastic|default("") }}@localhost:9200/_snapshot/Backup/snapshot_1?wait_for_completion=true' -H 'Content-Type: application/json' -d '{"indices": "{{ ES_INDICES }}","ignore_unavailable": true,"include_global_state": false}'
......@@ -6,7 +6,7 @@
#ES_HOME=/usr/share/elasticsearch
# Elasticsearch Java path
JAVA_HOME=/usr/lib/jvm/java-{{ java_version }}-openjdk-amd64/bin/java
JAVA_HOME=/usr/lib/jvm/java-{{ java_version }}-openjdk-amd64
# Elasticsearch configuration directory
ES_PATH_CONF=/etc/elasticsearch
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment