How to backup elasticsearch¶
To make backup of ElasticSearch we will use snapshot feature. You can read more about snapshots on ElasticSearch documentation (https://www.elastic.co/guide/en/elasticsearch/reference/2.2/modules-snapshots.html).
Preparing environment¶
ElasticSearch needs to place where backup will be stored.
- Create directory on container with correct permissions. You can attach volumen to bellow directory.
docker exec -it open_loyalty_elk bash
mkdir /usr/share/elasticsearch/backups
chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/backups
- Change ElasticSearch configuration in order to set created directory as backup place. Open file /usr/share/elasticsearch/config/elasticsearch.yml and add bellow line.
path.repo: ["/usr/share/elasticsearch/backups"]
- Restart ElasticSearch container in order to reload configuration.
Making snapshot¶
- To make snapshot open ElasticSearch container and execute:
docker exec -it open_loyalty_elk bash
curl -X PUT "localhost:9200/_snapshot/my_backup/snapshot_1?wait_for_completion=true"
- You can check all available snapshots on ElasticSearch cluster:
docker exec -it open_loyalty_elk bash
curl -X GET "localhost:9200/_snapshot/my_backup/_all?pretty"
Restoring snapshot¶
- To restore backup we have to log in on container.
docker exec -it open_loyalty_elk bash
- Before making snapshot we have to make sure that all indexes are closed.
curl -X POST "localhost:9200/_all/_close"
- Restore snapshot.
curl -X POST "localhost:9200/_snapshot/my_backup/snapshot_1/_restore"