Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

repository_missing_exception snapshot and restore in Elasticsearch

I have to transfer an Elasticsearch index on a Windows machine to an Ubuntu Machine. I decided to take a snapshot of the index and then try to restore it on the other system.

I was successfully able to snapshot the index on the windows machine. On the windows machine in elasticsearch.yml I had path.repo: ["F:\\mount\\backups"].

So, under mount I had:

.
└── backups
    └── old_backup
        ├── index
        ├── indices
        │   └── old_index
        │       ├── 0
        │       ├── 1
        │       ├── 2
        │       ├── 3
        │       ├── 4
        │       └── meta-snapshot_to_ubuntu.dat
        ├── meta-snapshot_to_ubuntu.dat
        └── snap-snapshot_to_ubuntu.dat

where snapshot_to_ubuntu is the name of the snapshot I made on Windows.

I placed this snapshot in ~/Documents/mount on the ubuntu machine and start an instance of ES 2.3.0 with path.repo: ["/home/animesh/Documents/mount/backups"] in elasticsearch.yml.

I run the following on the command line:

curl -XGET localhost:9200/_snapshot/old_backup/snapshot_to_ubuntu?pretty=1

and get

{
  "error" : {
    "root_cause" : [ {
      "type" : "repository_missing_exception",
      "reason" : "[old_backup] missing"
    } ],
    "type" : "repository_missing_exception",
    "reason" : "[old_backup] missing"
  },
  "status" : 404
}

Where am I going wrong?

UPDATE:

I ran the following curl command:

curl -X POST http://localhost:9200/_snapshot/old_backup/snapshot_to_ubuntu/_restore

and I get:

{
  "error": {
    "root_cause": [
      {
        "type": "repository_missing_exception",
        "reason": "[old_backup] missing"
      }
    ],
    "type": "repository_missing_exception",
    "reason": "[old_backup] missing"
  },
  "status": 404
}
like image 267
Animesh Pandey Avatar asked May 14 '16 21:05

Animesh Pandey


1 Answers

I had a similar issue and I would like to share with you how I figured it out. I will write all steps, hope it may helps other people as well.

I had to transfer an Elasticsearch index on a GCP server to my Local Machine. I decided to take a snapshot of the index and then try to restore it on my Local machine.

I'm assuming you already have the snapshot/s

The steps are:

  1. Create a directory on your local machine with the snapshot/s you want to restore

  2. Navigate to elasticsearch.yml file. For example, on my local machine, you can find the file here: /usr/local/Cellar/elasticsearch/7.8.1/libexec/config/elasticsearch.yml

  3. add the repository path: path.repo: [PATH_TO_BACKUP_DIR] on the elasticsearch.yml file. For example: path.repo: ["/mount/backups", "/mount/longterm_backups"]

  4. save, exit, and restart elasticsearch

  5. After all nodes are restarted, the following command can be used to register the shared file system repository with the name my_fs_backup

  6. curl -X PUT "localhost:9200/_snapshot/my_fs_backup?pretty" -H 'Content-Type: application/json' -d' { "type": "fs", "settings": { "location": "PATH_TO_BACKUP_DIR", // Example: location" : "/usr/local/etc/elasticsearch/elastic-backup" "compress": true } }'

  7. Check your configuration: curl -X GET "localhost:9200/_snapshot/_all?pretty"

  8. Restore from snapshot:

    8.1 Get all snapshots: curl -X GET "localhost:9200/_snapshot/my_fs_backup/*?pretty

You will get this screen: enter image description here

Pick the snapshot you want (In case you have more than one)

Use this command to restore:

curl -X POST "localhost:9200/_snapshot/BACKUP_NAME/SNAPSHOT_ID/_restore?pretty" -H 'Content-Type: application/json' -d'
       {
        "indices": "users, events",
        "ignore_unavailable": true,
        "include_global_state": true
       }

For example:

 curl -X POST "localhost:9200/_snapshot/my_fs_backup/elastic-snapshot-2020.09.05-lwul1zb9qaorq0k9vmd5rq/_restore?pretty" -H 'Content-Type: application/json' -d'
{
    "indices": "users, events",
    "ignore_unavailable": true,
    "include_global_state": true
 }

Pay attention that I imported only 2 indices users and events

Hope it helps 😃

More info and extended tutorials: Elastic website, jee-appy blogspot

like image 71
Adi Azarya Avatar answered Nov 08 '22 05:11

Adi Azarya