Loading...

Backup Kibana

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

Used:   elasticsearch v2.3.1 

Kibana is the visual web interface for elasticsearch. You can create searches, visualisations and dashboards. Sometimes you spend a lot of valuable work into them. Therefore is essential to have some kind of backup for Kibana. The Kibana data itself, is stored in Elasticsearch in the .kibana index. One way is to use the snapshot and restore capability of Elasticsearch.

I created two scripts, that runs in Jenkins. The first script is a daily snapshot and the second script is a monthly snapshot. From there we are capable to restore the snapshot from a daily or monthly basis. These scripts only create backup from kibana, which is not very large. Other indices aren’t in scope.

The daily snapshot:

SNAPSHOT=snapshot_$(date +%u)
# Test
echo -n "Delete previous snapshot from test-cluster"
curl -XDELETE "http://localhost:9200/_snapshot/kibana/$SNAPSHOT" -s
echo -n "Create new snapshot for test-cluster"
curl -XPUT "http://localhost:9200/_snapshot/kibana/$SNAPSHOT" -s -d '{ "indices": ".kibana",  "ignore_unavailable": "true",  "include_global_state": false }'
# Prod
echo -n "Delete previous snapshot from prod-cluster"
curl -XDELETE "http://elasticsearch:9200/_snapshot/kibana_prod/$SNAPSHOT" -s
echo -n "Create new snapshot for prod-cluster"
curl -XPUT "http://elasticsearch:9200/_snapshot/kibana_prod/$SNAPSHOT"  -s -d '{ "indices": ".kibana",  "ignore_unavailable": "true",  "include_global_state": false }'

The Jenkins schedule, e.g. would last have run at Sunday, May 22, 2016 11:12:54 PM CEST; would next run at Monday, May 23, 2016 11:12:54 PM CEST.

H 23 * * *

The monthly snapshot:

SNAPSHOT=backup_$(date +%m)
# Test
echo -n "Create monthly snapshot for test-cluster"
curl -XDELETE "http://localhost:9200/_snapshot/kibana/$SNAPSHOT" -s
curl -XPUT "http://localhost:9200/_snapshot/kibana/$SNAPSHOT" -s -d '{ "indices": ".kibana",  "ignore_unavailable": "true",  "include_global_state": false }'
# Prod
echo -n "Create monthly snapshot for prod-cluster"
curl -XDELETE "http://elasticsearch:9200/_snapshot/kibana_prod/$SNAPSHOT" -s
curl -XPUT "http://elasticsearch:9200/_snapshot/kibana_prod/$SNAPSHOT" -s -d '{ "indices": ".kibana",  "ignore_unavailable": "true",  "include_global_state": false }'

The Jenkins schedule, e.g. would last have run at Sunday, May 1, 2016 12:16:07 AM CEST; would next run at Wednesday, June 1, 2016 12:16:07 AM CEST.

H 0 1 * *
Please remember the terms for blog comments.