elasticsearch/docs/reference/snapshot-restore/apis/get-snapshot-api.asciidoc
Gordon Brown 3f6472de74
Introduce "Feature States" for managing snapshots of system indices (#63513)
This PR expands the meaning of `include_global_state` for snapshots to include system indices. If `include_global_state` is `true` on creation, system indices will be included in the snapshot regardless of the contents of the `indices` field. If `include_global_state` is `true` on restoration, system indices will be restored (if included in the snapshot), regardless of the contents of the `indices` field. Index renaming is not applied to system indices, as system indices rely on their names matching certain patterns. If restored system indices are already present, they are automatically deleted prior to restoration from the snapshot to avoid conflicts.

This behavior can be overridden to an extent by including a new field in the snapshot creation or restoration call, `feature_states`, which contains an array of strings indicating the "feature" for which system indices should be snapshotted or restored. For example, this call will only restore the `watcher` and `security` system indices (in addition to `index_1`):

```
POST /_snapshot/my_repository/snapshot_2/_restore
{
  "indices": "index_1",
  "include_global_state": true,
  "feature_states": ["watcher", "security"]
}
```

If `feature_states` is present, the system indices associated with those features will be snapshotted or restored regardless of the value of `include_global_state`. All system indices can be omitted by providing a special value of `none` (`"feature_states": ["none"]`), or included by omitting the field or explicitly providing an empty array (`"feature_states": []`), similar to the `indices` field.

The list of currently available features can be retrieved via a new "Get Snapshottable Features" API:
```
GET /_snapshottable_features
```

which returns a response of the form:
```
{
    "features": [
        {
            "name": "tasks",
            "description": "Manages task results"
        },
        {
            "name": "kibana",
            "description": "Manages Kibana configuration and reports"
        }
    ]
}
```

Features currently map one-to-one with `SystemIndexPlugin`s, but this should be considered an implementation detail. The Get Snapshottable Features API and snapshot creation rely upon all relevant plugins being installed on the master node.

Further, the list of feature states included in a given snapshot is exposed by the Get Snapshot API, which now includes a new field, `feature_states`, which contains a list of the feature states and their associated system indices which are included in the snapshot. All system indices in feature states are also included in the `indices` array for backwards compatibility, although explicitly requesting system indices included in a feature state is deprecated. For example, an excerpt from the Get Snapshot API showing `feature_states`:
```
"feature_states": [
    {
        "feature_name": "tasks",
        "indices": [
            ".tasks"
        ]
    }
],
"indices": [
    ".tasks",
    "test1",
    "test2"
]
```

Co-authored-by: William Brafford <william.brafford@elastic.co>
2021-02-11 11:55:14 -07:00

257 lines
7.1 KiB
Text

[[get-snapshot-api]]
=== Get snapshot API
++++
<titleabbrev>Get snapshot</titleabbrev>
++++
Retrieves information about one or more snapshots.
////
[source,console]
----
PUT /_snapshot/my_repository
{
"type": "fs",
"settings": {
"location": "my_backup_location"
}
}
PUT /_snapshot/my_repository/my_snapshot?wait_for_completion=true
PUT /_snapshot/my_repository/snapshot_2?wait_for_completion=true
----
// TESTSETUP
////
[source,console]
----
GET /_snapshot/my_repository/my_snapshot
----
[[get-snapshot-api-request]]
==== {api-request-title}
`GET /_snapshot/<repository>/<snapshot>`
[[get-snapshot-api-prereqs]]
==== {api-prereq-title}
* If the {es} {security-features} are enabled, you must have the
`monitor_snapshot`, `create_snapshot`, or `manage`
<<privileges-list-cluster,cluster privilege>> to use this API.
[[get-snapshot-api-desc]]
==== {api-description-title}
Use the get snapshot API to return information about one or more snapshots, including:
* Start and end time values
* Version of {es} that created the snapshot
* List of included indices
* Current state of the snapshot
* List of failures that occurred during the snapshot
[[get-snapshot-api-path-params]]
==== {api-path-parms-title}
`<repository>`::
(Required, string)
Comma-separated list of snapshot repository names used to limit the request.
Wildcard (`*`) expressions are supported.
+
To get information about all snapshot repositories registered in the
cluster, omit this parameter or use `*` or `_all`.
`<snapshot>`::
(Required, string)
Comma-separated list of snapshot names to retrieve. Also accepts wildcards (`*`).
+
* To get information about all snapshots in a registered repository, use a wildcard (`*`) or `_all`.
* To get information about any snapshots that are currently running, use `_current`.
+
NOTE: Using `_all` in a request fails if any snapshots are unavailable.
Set <<get-snapshot-api-ignore-unavailable,`ignore_unavailable`>> to `true` to return only available snapshots.
[role="child_attributes"]
[[get-snapshot-api-request-body]]
==== {api-request-body-title}
[[get-snapshot-api-ignore-unavailable]]
`ignore_unavailable`::
(Optional, Boolean)
If `false`, the request returns an error for any snapshots that are unavailable. Defaults to `false`.
+
If `true`, the request ignores snapshots that are unavailable, such as those that are corrupted or temporarily cannot be returned.
`verbose`::
(Optional, Boolean)
If `true`, returns all available information about a snapshot. Defaults to `true`.
+
If `false`, omits additional information about the snapshot, such as version information, start and end times, and the number of snapshotted shards.
[role="child_attributes"]
[[get-snapshot-api-response-body]]
==== {api-response-body-title}
`snapshot`::
(string)
Name of the snapshot.
`uuid`::
(string)
Universally unique identifier (UUID) of the snapshot.
`version_id`::
(int)
Build ID of the {es} version used to create the snapshot.
`version`::
(float)
{es} version used to create the snapshot.
`indices`::
(array)
List of indices included in the snapshot.
`data_streams`::
(array)
List of <<data-streams,data streams>> included in the snapshot.
`include_global_state`::
(Boolean)
Indicates whether the current cluster state is included in the snapshot.
[[get-snapshot-api-feature-states]]
`feature_states`::
(array)
List of feature states which were included when the snapshot was taken,
including the list of system indices included as part of the feature state. The
`feature_name` field of each can be used in the `feature_states` parameter when
restoring the snapshot to restore a subset of feature states. Only present if
the snapshot includes one or more feature states.
`start_time`::
(string)
Date timestamp of when the snapshot creation process started.
`start_time_in_millis`::
(long)
The time, in milliseconds, when the snapshot creation process started.
`end_time`::
(string)
Date timestamp of when the snapshot creation process ended.
`end_time_in_millis`::
(long)
The time, in milliseconds, when the snapshot creation process ended.
`duration_in_millis`::
(long)
How long, in milliseconds, it took to create the snapshot.
[[get-snapshot-api-response-failures]]
`failures`::
(array)
Lists any failures that occurred when creating the snapshot.
`shards`::
(object)
Contains a count of shards in the snapshot.
+
.Properties of `shards`
[%collapsible%open]
====
`total`::
(integer)
Total number of shards included in the snapshot.
`successful`::
(integer)
Number of shards that were successfully included in the snapshot.
`failed`::
(integer)
Number of shards that failed to be included in the snapshot.
====
`state`::
+
--
(string)
The snapshot `state` can be one of the following values:
.Values for `state`
[%collapsible%open]
====
`IN_PROGRESS`::
The snapshot is currently running.
`SUCCESS`::
The snapshot finished and all shards were stored successfully.
`FAILED`::
The snapshot finished with an error and failed to store any data.
`PARTIAL`::
The global cluster state was stored, but data of at least one shard was not stored successfully.
The <<get-snapshot-api-response-failures,`failures`>> section of the response contains more detailed information about shards
that were not processed correctly.
====
--
[[get-snapshot-api-example]]
==== {api-examples-title}
The following request returns information for `snapshot_2` in the `my_repository` repository.
[source,console]
----
GET /_snapshot/my_repository/snapshot_2
----
The API returns the following response:
[source,console-result]
----
{
"responses": [
{
"repository": "my_repository",
"snapshots": [
{
"snapshot": "snapshot_2",
"uuid": "vdRctLCxSketdKb54xw67g",
"version_id": <version_id>,
"version": <version>,
"indices": [],
"data_streams": [],
"feature_states": [],
"include_global_state": true,
"state": "SUCCESS",
"start_time": "2020-07-06T21:55:18.129Z",
"start_time_in_millis": 1593093628850,
"end_time": "2020-07-06T21:55:18.129Z",
"end_time_in_millis": 1593094752018,
"duration_in_millis": 0,
"failures": [],
"shards": {
"total": 0,
"failed": 0,
"successful": 0
}
}
]
}
]
}
----
// TESTRESPONSE[s/"uuid": "vdRctLCxSketdKb54xw67g"/"uuid": $body.responses.0.snapshots.0.uuid/]
// TESTRESPONSE[s/"version_id": <version_id>/"version_id": $body.responses.0.snapshots.0.version_id/]
// TESTRESPONSE[s/"version": <version>/"version": $body.responses.0.snapshots.0.version/]
// TESTRESPONSE[s/"start_time": "2020-07-06T21:55:18.129Z"/"start_time": $body.responses.0.snapshots.0.start_time/]
// TESTRESPONSE[s/"start_time_in_millis": 1593093628850/"start_time_in_millis": $body.responses.0.snapshots.0.start_time_in_millis/]
// TESTRESPONSE[s/"end_time": "2020-07-06T21:55:18.129Z"/"end_time": $body.responses.0.snapshots.0.end_time/]
// TESTRESPONSE[s/"end_time_in_millis": 1593094752018/"end_time_in_millis": $body.responses.0.snapshots.0.end_time_in_millis/]
// TESTRESPONSE[s/"duration_in_millis": 0/"duration_in_millis": $body.responses.0.snapshots.0.duration_in_millis/]