Skip to content

Instantly share code, notes, and snippets.

@shadiakiki1986
Last active May 6, 2019 12:13
Show Gist options
  • Save shadiakiki1986/981d8f65e9fdc11f63fb84f0555fba07 to your computer and use it in GitHub Desktop.
Save shadiakiki1986/981d8f65e9fdc11f63fb84f0555fba07 to your computer and use it in GitHub Desktop.
Restoring an elasticsearch snapshot

General

These are steps to restore an elasticsearch snapshot from one machine to another

Steps

Copy zip of snapshot from s3

sudo mkdir /data
sudo chmod 777 -R /data
aws s3 cp "s3://enel-aws/elasticsearch_snapshots.zip" .
unzip elasticsearch_snapshots.zip -d /data/

Install opendistro for elasticsearch

Add the folder for snapshots to "/etc/elasticsearch/elasticsearch.yml"

path.repo: ["/data/elasticsearch_snapshot"]

Restart elasticsearch

sudo systemctl restart elasticsearch.service

Install kibana

Go to Kibana "Dev tools" to run queries below

Test

GET /
Equivalent of curl call:
curl -u admin:admin --insecure -XGET https://localhost:9200

List repositories

GET _cat/repositories
# empty

Add repository

PUT _snapshot/my_fs_backup
{
  "type": "fs",
  "settings" : {
     "compress" : "true",
     "location" : "/data/elasticsearch_snapshots",
     "max_snapshot_bytes_per_sec" : "5000mb"
   }


or

curl -u admin:admin --insecure  -H 'Content-Type: application/json' -XPUT \
  https://localhost:9200/_snapshot/my_fs_backup \
  -d '{
  "type": "fs",
  "settings": {
    "location": "/data/elasticsearch_snapshot",
    "compress": true
  }
}'

List snapshots in repo

GET _cat/repositories
# my_fs_backup

List all snapshots in repository

GET /_snapshot/my_fs_backup/_all
{
  "snapshots" : [
    {
      "snapshot" : "snapshot_1",
      "uuid" : "dmAnazMrQtqsUYIrVt_WtQ",
      "version_id" : 6050499,
      "version" : "6.5.4",
      "indices" : [
        "modifyclusteriamroles_anon",
        "deletetable_anon",
        ...

Restore from snapshot (doesnt work due to above empty list)

POST /_snapshot/my_fs_backup/snapshot_1/_restore
{
 "indices": "*_anon",
 "include_global_state": false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment