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.
- 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:
- After creating the repository we can take the snapshot of all indices using the following expression:
- 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:
"indices": "index1, index2"
- If we want to see the snapshot details then we need to run the following expression:
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.
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 may like to read
Leave a comment
Sep 23, 2020, 2:38:00 PM | Anurag Srivastava
Sep 6, 2020, 5:20:33 PM | Anurag Srivastava
Jan 16, 2020, 11:43:29 AM | Anurag Srivastava
Jan 14, 2020, 10:22:34 AM | Anurag Srivastava
Jan 7, 2020, 7:15:34 PM | Anurag Srivastava
Jan 6, 2020, 7:30:13 PM | Anurag Srivastava
Jun 21, 2018, 4:58:11 AM | Anurag Srivastava
Jul 16, 2018, 5:00:02 PM | Anurag Srivastava
Mar 9, 2019, 8:20:38 AM | Anurag Srivastava