/
How to create snapshot and restore elasticsearch cluster data

eGov ERP DevOps

How to create snapshot and restore elasticsearch cluster data

Version Compatibility:

  • A snapshot of an index created in 5.x can be restored to 6.x.

  • A snapshot of an index created in 2.x can be restored to 5.x.

  • A snapshot of an index created in 1.x can be restored to 2.x.

Conversely, snapshots of indices created in 1.x cannot be restored to 5.x or 6.x, and snapshots of indices created in 2.x cannot be restored to 6.x.

Prerequisite: elasticsearch-6.5.1

Download: https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.1.deb

Install: sudo dpkg -i elasticsearch-6.5.1.deb

Note: if any other version of es is running in your machine please take care of es ports

 

SNAPSHOT DUMPING PROCESS: in this we are going to take snapshot dump of single index receipts-consumers index from running cluster.

Create a snapshot directory

mkdir -p /elasticseacrhData/es-backup chown -R elasticsearch:elasticsearch /elasticseacrhData/es-backup vi /etc/elasticsearch/elasticsearch.yml >> path.repo: ["/elasticseacrhData/es-backup"] service elasticsearch restart curl -XGET 'http://localhost:9200/_snapshot/_all?pretty'

Create Repository:

curl -XPUT -H "Content-Type: application/json;charset=UTF-8" 'http://localhost:9200/_snapshot/esbackup' -d '{ "type": "fs", "settings": { "location": "/elasticseacrhData/es-backup", "compress": true } }'
curl -XGET 'http://localhost:9200/_snapshot/_all?pretty

Complete snapshot:

curl -XPUT "http://localhost:9200/_snapshot/esbackup/{snapshot_name}?wait_for_completion=true"

Individual indices in the cluster:

curl -X PUT -H "Content-Type: application/json" "http://localhost:9200/_snapshot/esbackup/{snapshot_name}?wait_for_completion=true" -d ' { "indices": "index_1,index_2, index_3", "ignore_unavailable": true, "include_global_state": false }'
curl -XGET "http://localhost:9200/_snapshot/esbackup/_all?pretty"

 

RESTORING PROCESS: in this we are going to restore receipts-consumers index from es-backup.

  1. Download es-backup.tar.gz from this mail

  2. sudo mkdir -p /elasticsearchDataLocal

  3. sudo mv ~/es-backup.tar.gz /elasticsearchDataLocal/

  4. cd /elasticsearchDataLocal/

  5. sudo tar xzf  es-backup.tar.gz

  6. sudo chown -R elasticsearch:elasticsearch /elasticsearchDataLocal/es-backup

  7. add the path.repo in elasticsearch configuration file

  8. sudo vi /etc/elasticsearch/elasticsearch.yml: add path.repo: ["/elasticseacrhDataLocal/es-backup"]

  9. sudo service elasticsearch  restart

  10. Download postman collection from this mail

  11. Import collection to postman

  12. To check if we have any repositories already setup run: search_repo

  13. to register it as a repository run: register_esrestore_repo

  14. to check repo created run: search_registered_repo

  15. to restore es-backup run: restore_snap

  16. to verify index restored locally run: search_index

Related content

DevOps as a Culture