Elasticsearch Cluster: How to Restore a snapshot

Nuwan Chamara
3 min readDec 9, 2018

--

Hope you know how to create a snapshot and restore it on a single node elastic setup. It’s bit different when coming in to elastic cluster. I will briefly teach you that in this quick article.

In my scenario I will be creating a snapshot in a single node elastic setup and moving in to my another elastic cluster.

In order to use snapshot feature in a elastic cluster environment I must provide a folder which is shared among all the cluster nodes. Having a shared folder is the tough part in this exercise. So my plan is to share the folder and mount in to all the elastic servers.

What is an Elasticsearch Snapshot

Elasticsearch snapshot is a backup of an elastic index which can be used to restore data.

You can restore snapshots with different index names when you require creating lot of data for doing load tests.

Creating a snapshot

I will just skip this part as setup is same and only difference is how to make the rest call. So assume I have the snapshot files in the folder to be shared.

Setting up elastic cluster

Again I will not explain how to create a elastic cluster here. I expect you have a properly configured and running elastic cluster :)

My Setup

Centos 7

Elasticsearch 6.3.0

Setting up an elastic cluster for snapshots

I am working on a elastic cluster which is a three node cluster. As I mentioned earlier we must provide a shared folder to have snapshots. let’s now see how can we configure that.

Setting up the shared folder as an NFS server

The server where the snapshot is located must be shared, so others can access it.

Step 1: Install NFS-utils

yum -y install NFS-utils

Step 2: Edit exports file and add below line

vi /etc/exports

/esbackup *(rw,sync,no_subtree_check)

/esbackup is the folder I am trying to share

*- folder shared among all ip’s, can restrict if you require

Step 3: Reload the exports file

exportfs -a

Step 4: Set your folder permission

chmod -R 755 /esbackup/

Step 5: Make elasticsearch user as the owner of the folder

chown -R elasticsearch:elasticsearch /esbackup

Step 6: Now start following services

systemctl enable rpcbind
systemctl enable nfs-server
systemctl enable nfs-lock
systemctl enable nfs-idmap
systemctl enable nfs-idmap
systemctl start rpcbind
systemctl start nfs-server
systemctl start nfs-lock
systemctl start nfs-idmap
systemctl restart nfs-server

Now our folder is ready for sharing.

Mounting shared folder on client server

Now we must mount the shared folder on all Elasticsearch nodes so that they can access the contains.

Step 7: Create a folder for esbackup in node1

mkdir -p /mnt/nfs/esbackup

Step 8: Install nfs-utils in client node

yum install nfs-utils

Step 8: Mount server folder at client
Mount aa.aa.aa.aa:/esbackup to /mnt/nfs/esbackup/
aa.aa.aa.aa is my server ip.

mount -t nfs 35.196.200.5:/esbackup /mnt/nfs/esbackup/

Step 9: Verify

cd /mnt/nfs/esbackup/

Now you should be able to access.

Step 10: Permanent NFS mounting

We have mounted folder temporarily, that is after you done a restart you must redo all these changes. so lets make this permanent.

vi /etc/fstab

add this to the end

aa.aa.aa.aa:/esbackup /mnt/nfs/esbackup/ nfs defaults 0 0

Step 11: repeat step 7 to 11 for all the nodes.

Config Elasticsearch cluster for snapshots

We have completed the tough part, now let’s continue adding shared folder to the elasticsearch cluster.

Step 12: Set path.repo

add below line to the end of the elasicsearch.yml file

path.repo: [“/mnt/nfs/esbackup/”]

Step 13: Restart elasticsearch

systemctl restart elasticsearch

Repeat step 12 & 13 for all nodes

Step 14: Add a snapshot repo to the es cluster

Add a repository to the Elasticsearch cluster. Open Kibana dev tools and add a snapshot repo as following. I have used the same repo name as my source indexes where I created my snapshots. My repo name is nuwan-backup

PUT /_snapshot/nuwan-backup
{
“type”: “fs”,
“settings”: {
“location”: “/esbackup/”
}
}

Step 15: View all snapshots

Now we should be able to see all snapshots if we run this

GET /_snapshot/nuwan-backup/snapshot_*

If we have configured all above steps successfully this step must show all the steps in the snapshot folder.

Restore the snapshot

Step 16: Restore snapshot

Let’s restore snapshot_transactions-2018.12.03 as transactions-2018.12.03

POST /_snapshot/nuwan-backup/snapshot_transactions-2018.12.03/_restore
{
“indices”: “transactions-2018.12.03”,
“ignore_unavailable”: true,
“include_global_state”: true
}

All done. if we check the index names through kibana UI, we should be able to see new index created with the name as “transactions-2018.12.03”

--

--

No responses yet