Blog Detail

Covid-19 Tracker Ask Question

preview image DevOps
by Anurag Srivastava, Sep 16, 2019, 5:55:06 AM | 3 minutes |

Snapshot and Restore Elasticsearch Indices

In this blog, I am going to explain how we can take a snapshot of a single index or multiple indices to take the backup and how to restore the snapshot. We can not take the backup of Elasticsearch by just copying the data directories of all the nodes as Elasticsearch keeps on changing the contents of its data directories. So how to take the backup and how to restore it? 

Elasticsearch provides a snapshot and restores API using which we can create the snapshot and can restore it. So to create the backup we need to do the following:

  • We first need to identify the directory location where we want to store the snapshot files. Let's say I want to store it in "/var/tmp/backups" directory.

  • We need to provide the directory access to Elasticsearch user so that Elasticsearch can write the snapshot files.
chown -R elasticsearch. /var/tmp/backups

  • Now we need to tell Elasticsearch that this is our snapshot directory location. For that, we need to add the "repo.path" setting in elasticsearch.yml file.
path.repo: ["/var/tmp/backups"]

  • Here we are using the local file system directory for storing the snapshot but the same can be stored on the cloud as well. But in this blog, we will focus on file system based snapshots only.

  • We first need to create the repository which would be used for taking a snapshot and to restore. We can create the repository using the following expression:
PUT _snapshot/anurag_backup
 "type": "fs",
 "settings": {
   "location": "/var/tmp/backups"

  • After creating the repository we can take the snapshot of all indices using the following expression:
PUT _snapshot/anurag_backup/snapshot_all_indices

  • If we want to take a snapshot of one or more index only then we can specify the index name in a comma-separated form, please refer to the below expression:
PUT _snapshot/anurag_backup/snapshot_some_indices
 "indices": "index1, index2"

  • If we want to see the snapshot details then we need to run the following expression:
GET _snapshot/anurag_backup/snapshot_all_indices 

The above expression provides us the snapshot details like version, list of indices, start time, end time, duration in milis, etc.

  • We can restore the snapshot by appending the _restore endpoint after the snapshot name.
POST _snapshot/anurag_backup/snapshot_all_indices/_restore

We can test the restore process by first creating some indices, taking their snapshot, and then deleting those indices. After this, we can restore the snapshot to get the indices that we have deleted. I hope you can now create the snapshots and can restore them, in case of any query please leave your comment.

Other Blogs on Elastic Stack:

How to create Elasticsearch Cluster
Bucket Aggregation in Elasticsearch

Metrics Aggregation in Elasticsearch
Configure Logstash to push MySQL data into Elasticsearch
Configure Logstash to push MongoDB data into Elasticsearch
Load CSV Data into Elasticsearch
Wildcard and Boolean Search in Elasticsearch
Elasticsearch Rest API
Basics of Data Search in Elasticsearch
Elasticsearch Rest API
Log analysis with Elastic stack 
Elasticsearch Installation and Configuration on Ubuntu 14.04
Introduction to Elasticsearch

If you found this article interesting, then you can explore “Mastering Kibana 6.0”, “Kibana 7 Quick Start Guide”, “Learning Kibana 7”, and “Elasticsearch 7 Quick Start Guide” books to get more insight about Elastic Stack, how to perform data analysis, and how you can create dashboards for key performance indicators using Kibana.

You can also follow me on:

- LinkedIn:

- Twitter:

- Medium:

Comments (0)

Leave a comment

Related Blogs

Introduction to Cloud Computing

Sep 23, 2020, 2:38:00 PM | Anurag Srivastava

Monitoring website uptime using Kibana

Sep 6, 2020, 5:20:33 PM | Anurag Srivastava

Monitoring Application using Elastic APM

Jan 16, 2020, 11:43:29 AM | Anurag Srivastava

Configuring Django application with Elastic APM

Jan 14, 2020, 10:22:34 AM | Anurag Srivastava

Introduction to Elastic APM

Jan 7, 2020, 7:15:34 PM | Anurag Srivastava

Why monitoring is important?

Jan 6, 2020, 7:30:13 PM | Anurag Srivastava

Top Blogs

Configure SonarQube Scanner with Jenkins

Jun 21, 2018, 4:58:11 AM | Anurag Srivastava

Execute Commands on Remote Machines using sshpass

Jul 16, 2018, 5:00:02 PM | Anurag Srivastava

Importing MongoDB data into Elasticsearch

Mar 9, 2019, 8:20:38 AM | Anurag Srivastava

Importing MySQL data into Elasticsearch

Feb 9, 2019, 12:06:18 PM | Anurag Srivastava

Configure Jenkins for Automated Code Deployment

Jun 13, 2018, 3:44:01 PM | Anurag Srivastava

Deploying Angular code using Python script

Jun 26, 2018, 4:50:18 PM | Anurag Srivastava