Elasticsearch Snapshot And Restore Guide
Posted By : Mohd Adnan | 01-Jun-2018
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
Repositories
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 or 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.
Request for Proposal
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Mohd Adnan
Adnan, an experienced Backend Developer, boasts a robust expertise spanning multiple technologies, prominently Java. He possesses an extensive grasp of cutting-edge technologies and boasts hands-on proficiency in Core Java, Spring Boot, Hibernate, Apache Kafka messaging queue, Redis, as well as relational databases such as MySQL and PostgreSQL. Adnan consistently delivers invaluable contributions to a variety of client projects, including Vision360 (UK) - Konfer, Bitsclan, Yogamu, Bill Barry DevOps support, enhedu.com, Noorisys, One Infinity- DevOps Setup, and more. He exhibits exceptional analytical skills alongside a creative mindset. Moreover, he possesses a fervent passion for reading books and exploring novel technologies and innovations.