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.
Download es-backup.tar.gz from this mail
sudo mkdir -p /elasticsearchDataLocal
sudo mv ~/es-backup.tar.gz /elasticsearchDataLocal/
cd /elasticsearchDataLocal/
sudo tar xzf es-backup.tar.gz
sudo chown -R elasticsearch:elasticsearch /elasticsearchDataLocal/es-backup
add the path.repo in elasticsearch configuration file
sudo vi /etc/elasticsearch/elasticsearch.yml: add path.repo: ["/elasticseacrhDataLocal/es-backup"]
sudo service elasticsearch restart
Download postman collection from this mail
Import collection to postman
To check if we have any repositories already setup run: search_repo
to register it as a repository run: register_esrestore_repo
to check repo created run: search_registered_repo
to restore es-backup run: restore_snap
to verify index restored locally run: search_index
Related content
DevOps as a Culture