Elasticsearch: Restoring Snapshots

Before proceeding with the following steps, connect to the target machine or use the machine’s external IP address (if you have the necessary permissions).

List all Indexes in Elasticsearch:

curl -u "user:password" -X GET "localhost:9200/_cat/indices?v"

Important: Elasticsearch cannot restore an open index with the same name. You must delete or rename the existing index before restoring.

Option 1: Close the Existing Index

Close the index to allow restoration:

curl -u "user:password" -X POST "http://localhost:9200/products/_close"

Option 2: Delete the Existing Index

Delete the index to make way for the restoration:

curl -u "user:password" -X DELETE "http://localhost:9200/products"

List All Available Snapshots

Verify all snapshots stored in the repository (for quick checks and operational overviews):

curl -u "user:password" -X GET "http://localhost:9200/_cat/snapshots/test-elasticsearch-space?v&s=id&pretty"

To retrieve detailed information about a specific snapshot

curl -u "user:password" -X GET "http://localhost:9200/_snapshot/test-elasticsearch-space/snapshot_20241211144811?pretty"

Restore the Snapshot

Restore a specific index from the snapshot:

curl -u "user:password" -X POST "http://localhost:9200/_snapshot/test-elasticsearch-space/snapshot_20241211144811/_restore" -H 'Content-Type: application/json' -d'
{
  "indices": "products"
}
'

Restore with a New Name

Restore the snapshot to a new index name:

curl -u "user:password" -X POST "http://localhost:9200/_snapshot/test-elasticsearch-space/snapshot_20241211144811/_restore" -H 'Content-Type: application/json' -d'
{
  "indices": "products",
  "rename_pattern": "products",
  "rename_replacement": "restored_products"
}
'

Verify the Restored Index

Verify that the restored index is available:

curl -u "user:password" -X GET "http://localhost:9200/restored_products/_search?pretty"

Comments

Leave a Reply