Animesh Pandey
Animesh Pandey

Reputation: 6018

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
}

Upvotes: 8

Views: 17335

Answers (3)

Adi Azarya
Adi Azarya

Reputation: 4473

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

Upvotes: 6

Markus
Markus

Reputation: 2153

NOTE: This solution uses slightly different repository storage, but the behaviour is expected to be the same!

I know it's a zombie question, but I currently stumbled of this, while testing restore procedure of ElasticSnapshots with Azure Repository plugin.

I created a snapshot on our old PAAS Openstack and tried restoring on a fresh Azure Elastic cluster where I tested the connectivity of Azure repositories before. I still got the "repository location" in my case:

{
  "type": "azure",
  "settings": {
    "container": "restore",
    "chunk_size": "32MB",
    "compress": true
  }
}

But restoring always got the me the missing repository exception:

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

Turns out another branch got deployed on my test Azure k8s cluster which removed the Azure repository plugin and with it the connectivity to the repository. Even restoring the plugin did not help fixing the missing_repository_exception

Carefully re-reading the docs (https://www.elastic.co/guide/en/elasticsearch/reference/7.9/snapshots-register-repository.html) gave me this:

You can unregister a repository using the delete snapshot repository API. When a repository is unregistered, Elasticsearch only removes the reference to the location where the repository is storing the snapshots. The snapshots themselves are left untouched and in place.

So what solved the missing_repository_exception in my case was doing a "bit scary":

DELETE /_snapshot/restore

and then recreating the snapshot location with:

PUT https://localhost:9200/_snapshot/restore --data '
 {
   "type": "azure",
   "settings": {
     "container": "restore",
     "chunk_size": "32MB",
     "compress": true
   }
 }'

Then the previously failing snapshot restore command succeded:

 POST https://localhost:9200/_snapshot/restore/snapshot_2020810/_restore
 {"accepted":true}

Upvotes: 0

alpert
alpert

Reputation: 4655

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

That command creates snapshot. Because you didnt create a repository on ubuntu side, you get error.

What you want is to restore so you should use _restore endpoint:

POST /_snapshot/old_backup/snapshot_to_ubuntu/_restore

Check:https://www.elastic.co/guide/en/elasticsearch/reference/2.3/modules-snapshots.html#_restore

Upvotes: -1

Related Questions