← Back to list

Snapshot and Restore — Elasticsearch

André Coelho · 2022-10-30 12:39 · 12 claps · 1.4 min read
#elasticsearch-snapshot #elasticsearch-restore
Open on Medium ↗

Snapshot and Restore — Elasticsearch

In this post I intend to demonstrate how to use the Snapshot API to perform backups and restore indices.

The backup process must follow a few steps and respecting each of them we will be successful in the operation. Let’s start!

Create directory

In your environment you will need to create the directory where the data repository will be.

mkdir /mnt/backups/movies_repo

Confirm that in this repository the elasticsearch user has owner privileges. If not, run the command below:

chown elasticsearch:elasticsearch /mnt/backups/movies_repo

Editing elasticsearch.yml

With the directory created it is necessary to edit the elasticsearch.yml adding the entry:

path.repo: "/mnt/backups/movies_repo"

Remember that after this change it will be necessary to restart elasticsearch.

systemctl restart elasticsearch

Register repository

Now let’s use the Snapshot API to register the repository:

POST _snapshot/movies_repository
{
  "type": "fs",
  "settings": {
    "location": "/mnt/backups/movies_repo"
  }
}

To verify the creation run:

GET _snapshot/movies_repository/

Create Snapshot

To create the snapshot run:

POST _snapshot/movies_repository/idx_movies_backup
{
  "indices": "idx_movies",
  "include_global_state": true
}

In the parameter “indices” I informed which index I want to run the snapshot and kept the “include_global_state” as true.

Run command bellow for see snapshot:

GET _snapshot/movies_repository/idx_movies_backup

Output:

{
  "snapshots" : [
    {
      ...
      "indices" : [
        "idx_movies",
        ...
      ],
      "feature_states" : [
        ...
      ]
    }
  ]
}

Restore Snapshot

Now if we want to restore the snapshot, just run:

POST _snapshot/movies_repository/idx_movies_backup/_restore
{
  "indices": "idx_movies",
  "rename_pattern": "(.+)",
  "rename_replacement": "$1_restore"
}

Note that applying the rename pattern as I want the restored index to be called idx_movies_restore.

Checking the indices:

As you have seen by following the steps the snapshot and restore operation does not fail. Remembering that this was one of the ways.

Remember, for more information and depth, always consult the documentation.

References

[embed]Snapshot and restore APIs | Elasticsearch Guide [8.4] | Elastic You can use the following APIs to set up snapshot repositories, manage snapshot backups, and restore snapshots to a…www.elastic.co


메타데이터
post_id
3fd6b7bbf874
slug
snapshot-and-restore-elasticsearch-3fd6b7bbf874
url
https://medium.com/@andre.luiz1987/snapshot-and-restore-elasticsearch-3fd6b7bbf874
canonical_url
https://medium.com/@andre.luiz1987/snapshot-and-restore-elasticsearch-3fd6b7bbf874
author_url
https://medium.com/@andre.luiz1987
status
ok
fetched_at
2026-09-01 17:46:57