Elastic Search

Elasticsearch Get Snapshot Status

This article explores how we can fetch the detailed description of each shard participating in a given snapshot.

To fetch the status of a given snapshot in Elasticsearch, we use the Get snapshot status API endpoint.

Request Syntax

The request syntax is as shown in the following:

GET _snapshot/_status
GET _snapshot/<repository>/_status
GET _snapshot/<repository>/<snapshot>/_status

The request supports the following path parameters:

  1. <repository> – The name of the snapshot repository. This is very useful to limit the scope of the request to a given repository instead of the system wide query.
  2. <snapshot> – Specifies the name of a target snapshot. You can also specify the multiple snapshots as a comma-separated list.

We can omit the snapshot in the request parameter to fetch an information about the currently running snapshots.

Response Body

The request should return a detailed information about the snapshot. Such information included in the response are:

  1. Repository – The name of the repository in which the snapshot resides.
  2. Snapshot – The name of the snapshot.
  3. uuid – UUID of the snapshot.
  4. State – The current state of the snapshot. The snapshot can be in the following states:
  5.   a. FAILED – The snapshot that is finished with an error and fails to restore the backed up data.
      b. STARTED – Indicates that the snapshot is currently running.
      c. PARTIAL – Shows that the global cluster state is restored but the data of at least one shard failed to store successfully.
      d. SUCCESS – Indicates that the snapshot is finished successfully.

  6. Include_global_state – Indicates whether the global cluster state is included in the specified snapshot.
  7. Shard_stats – Shows the count of the shards.
  8. Stats – Details on the number of file count and the size of the files in the snapshot.

Those are some of the information returned from the snapshot status.

Elasticsearch Create Snapshot

To best illustrate how to use the Elasticsearch Get snapshot API, let us create a sample snapshot. Keep in mind that this section does not cover the basics of creating an Elasticsearch repository or other requirements for an Elasticsearch snapshot.

Check the documentation to learn more.

Suppose we have a repository called elk_bakcups, we can create a snapshot in that repository with the request as shown in the following:

curl -XPUT "http://localhost:9200/_snapshot/elk_backups/test_snapshot?wait_for_completion=true" -H "kbn-xsrf: reporting"

The previous request initializes the snapshot creation in the specified repository.

NOTE: The time required for the snapshot creation to complete depends on a number of factors.

Elasticsearch Get Snapshot Status

Once we initialize the snapshot creation process, we can check its status by running the following query:

curl -XGET "http://localhost:9200/_snapshot/elk_backups/test_snapshot/_status" -H "kbn-xsrf: reporting"

This should return a detailed information about the snapshot status. An example output is as shown in the following:

{
"snapshots": [
{
"snapshot": "test_snapshot",
"repository": "elk_backups",<strong>
</strong>      "uuid": "9oOJtTunR_WC-1a7NA-9WQ",
"state": "SUCCESS",
"include_global_state": true,
"shards_stats": {
"initializing": 0,
"started": 0,
"finalizing": 0,
"done": 94,
"failed": 0,
"total": 94
},
"stats": {
"incremental": {
"file_count": 282,
"size_in_bytes": 750304
},
"total": {
"file_count": 692,
"size_in_bytes": 62159894
},
"start_time_in_millis": 1663770043239,
"time_in_millis": 26212
},
"indices": {<strong>
</strong>        "my-data-stream": {
"shards_stats": {
"initializing": 0,
"started": 0,
"finalizing": 0,
"done": 1,
"failed": 0,
"total": 1
},
"stats": {
"incremental": {
"file_count": 0,
"size_in_bytes": 0
},
"total": {
"file_count": 10,
"size_in_bytes": 13518
},

-----------------OUTPUT TRUNCATED------------------------

In Kibana, you can check the snapshot status by navigating to the Stack Management – Snapshot and Restore section.

Select the target snapshot and view the details.

NOTE: Keep in mind that Kibana does not provide comprehensive details as provided by the Elasticsearch get snapshot status API.

Conclusion

In this post, we explored the fundamentals of working with the get snapshot status API which allows us to fetch a detailed information about a given snapshot.

Thanks for reading!

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list