Elasticsearch Snapshot And Restore Guide

Posted By : Mohd Adnan | 01-Jun-2018
Elasticsearch Snapshot and Restore
Image Credits: Slideshare
To create a snapshot of Elasticsearch indices or an entire cluster, Elasticsearch provides modules for the same, the snapshot and the restore module. The snapshots are created into a repository (shared file system, S3, or HDFS). The snapshots can be restored quicky but there's a limit to Elasticsearch versions that can read the index. This means that:
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 but cannot be restored to 5.x
Before any operation is performed for creating snapshot or restoration, a snapshot repository must be registered in Elasticsearch.
To register a repository, run the following command:
	curl -X PUT "localhost:9200/_snapshot/backup" 
	    -H 'Content-Type: application/json' 
	    -d '{  "type": "fs",  "settings": {    
	    "location": "location of your backup"   

Replace, the location with your directory path
Once a repository is registered in the Elasticsearch configuration, its information can be viewed using the following command:
curl -X GET "localhost:9200/_snapshot/my_backup"
which returns:
	  "my_backup": {
	    "type": "fs",
	    "settings": {
	      "compress": "true",
	      "location": "/mount/backups/my_backup"
_all is assumed as a repository name where repository name is not defined.
Elasticsearch will display information about all repositories that are currently registered in the cluster:
GET /_snapshot

	GET /_snapshot/_all

Shared File System Repository

The shared file system repository ("type": "fs") is used to store snapshots. To be able to register the shared file system repository, the location must be registered in the path.repo setting to impact all master and data nodes.
The following setting should be added to elasticsearch.yml file:
path.repo: ["/snapshots", "path to the your created directory for snapshot"]
To create a snapshot, you can use the following command:
curl -X PUT "localhost:9200/_snapshot/backup/snapshot_1" -H 'Content-Type: application/json' -d '
	  "indices": "indices followed by comma",
	  "ignore_unavailable": "true",
	  "include_global_state": false
To check the status of the snapshot or restoration process, use the following command
curl -X GET "localhost:9200/_snapshot/backup/snapshot_1/_status"
To restore from the created snapshot, you can use the following command:
curl -X POST "localhost:9200/_snapshot/backup/snapshot_1/_restore"
Hope that helps.

About Author

Author Image
Mohd Adnan

Adnan is a passionate enthusiastic learner, always searching for ways to expand knowledge. Proficient in Java & AWS Cloud Computing Services. As a coder, loves the logic and structure of coding, and always strive to write elegant and efficient code.

Request for Proposal

Name is required

Comment is required

Sending message..