2020-06-30 02:53:30 +08:00
[[create-snapshot-api]]
=== Create snapshot API
++++
<titleabbrev>Create snapshot</titleabbrev>
++++
2025-01-01 04:02:59 +08:00
.New API reference
[sidebar]
--
For the most up-to-date API details, refer to {api-es}/group/endpoint-snapshot[Snapshot and restore APIs].
--
2021-11-16 01:45:07 +08:00
<<snapshots-take-snapshot,Takes a snapshot>> of a cluster or specified data
streams and indices.
2020-06-30 02:53:30 +08:00
////
[source,console]
-----------------------------------
PUT /_snapshot/my_repository
{
"type": "fs",
"settings": {
"location": "my_backup_location"
}
}
-----------------------------------
// TESTSETUP
////
[source,console]
-----------------------------------
PUT /_snapshot/my_repository/my_snapshot
-----------------------------------
// TEST[s/my_snapshot/my_snapshot?wait_for_completion=true/]
[[create-snapshot-api-request]]
==== {api-request-title}
`PUT /_snapshot/<repository>/<snapshot>`
`POST /_snapshot/<repository>/<snapshot>`
2021-02-02 22:34:35 +08:00
[[create-snapshot-api-prereqs]]
==== {api-prereq-title}
* If the {es} {security-features} are enabled, you must have the
`create_snapshot` or `manage` <<privileges-list-cluster,cluster privilege>> to
use this API.
2020-06-30 02:53:30 +08:00
[[create-snapshot-api-path-params]]
==== {api-path-parms-title}
`<repository>`::
(Required, string)
2021-10-21 21:03:12 +08:00
Name of the snapshot repository.
2020-06-30 02:53:30 +08:00
`<snapshot>`::
(Required, string)
2021-10-21 21:03:12 +08:00
Name of the snapshot. Supports <<api-date-math-index-names,date math>>. Must be
unique within the snapshot repository.
2020-06-30 02:53:30 +08:00
2021-08-13 01:11:12 +08:00
[[create-snapshot-api-query-params]]
==== {api-query-parms-title}
2024-04-17 20:37:07 +08:00
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=master-timeout]
2021-08-13 01:11:12 +08:00
`wait_for_completion`::
(Optional, Boolean) If `true`, the request returns a response when the snapshot
is complete. If `false`, the request returns a response when the snapshot
initializes. Defaults to `false`.
2020-06-30 02:53:30 +08:00
[role="child_attributes"]
[[create-snapshot-api-request-body]]
==== {api-request-body-title}
2021-08-20 20:29:16 +08:00
// Set an attribute so we can reuse these params with anchors
:page-id: create-snapshot-api
// tag::snapshot-config[]
2021-10-21 21:03:12 +08:00
`expand_wildcards`::
+
--
(Optional, string) Determines how wildcard patterns in the `indices` parameter
match data streams and indices. Supports comma-separated values, such as
`open,hidden`. Defaults to `all`. Valid values are:
`all`:::
2023-08-23 16:41:35 +08:00
Match any data stream or index, including closed and <<multi-hidden,hidden>> ones.
2021-10-21 21:03:12 +08:00
`open`:::
Match open indices and data streams.
`closed`:::
Match closed indices and data streams.
`hidden`:::
Match hidden data streams and indices. Must be combined with `open`, `closed`,
or both.
`none`:::
Don't expand wildcard patterns.
--
2020-06-30 02:53:30 +08:00
`ignore_unavailable`::
2020-10-29 21:04:43 +08:00
(Optional, Boolean)
2021-08-20 20:29:16 +08:00
If `false`, the snapshot fails if any data stream or index in `indices` is
2022-12-12 17:18:27 +08:00
missing. If `true`, the snapshot ignores missing data
2021-08-20 20:29:16 +08:00
streams and indices. Defaults to `false`.
2020-06-30 02:53:30 +08:00
`include_global_state`::
+
--
2020-10-29 21:04:43 +08:00
(Optional, Boolean)
2021-10-21 21:03:12 +08:00
If `true`, include the cluster state in the snapshot. Defaults to `true`.
The cluster state includes:
2020-06-30 02:53:30 +08:00
2021-10-21 21:03:12 +08:00
include::restore-snapshot-api.asciidoc[tag=cluster-state-contents]
2020-06-30 02:53:30 +08:00
--
2021-10-21 21:03:12 +08:00
`indices`::
(Optional, string or array of strings)
Comma-separated list of data streams and indices to include in the snapshot.
2022-02-10 02:00:07 +08:00
Supports <<api-multi-index,multi-target syntax>>. Defaults to an empty array
2021-12-08 23:15:14 +08:00
(`[]`), which includes all regular data streams and regular indices. To exclude
2022-01-29 01:24:01 +08:00
all data streams and indices, use `-*`.
2021-10-21 21:03:12 +08:00
+
2021-12-08 23:15:14 +08:00
You can't use this parameter to include or exclude <<system-indices,system
indices or system data streams>> from a snapshot. Use
<<{page-id}-feature-states,`feature_states`>> instead.
2021-10-21 21:03:12 +08:00
2021-08-20 20:29:16 +08:00
[id="{page-id}-feature-states"]
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-12 02:55:14 +08:00
`feature_states`::
(Optional, array of strings)
2021-11-16 01:45:07 +08:00
<<feature-state,Feature states>> to include in the snapshot. To get a list of
possible values and their descriptions, use the <<get-features-api,get features
API>>.
2021-10-21 21:03:12 +08:00
+
If `include_global_state` is `true`, the snapshot includes all feature states by
default. If `include_global_state` is `false`, the snapshot includes no feature
states by default.
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-12 02:55:14 +08:00
+
2022-02-17 09:04:00 +08:00
Note that specifying an empty array will result in the default behavior. To
exclude all feature states, regardless of the `include_global_state` value,
specify an array with only the value `none` (`["none"]`).
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-12 02:55:14 +08:00
2020-06-30 02:53:30 +08:00
`metadata`::
2021-08-13 04:38:56 +08:00
(Optional, object)
2020-06-30 02:53:30 +08:00
Attaches arbitrary metadata to the snapshot, such as a record of who took the snapshot, why it was taken, or any other useful data. Metadata must be less than 1024 bytes.
2021-08-20 20:29:16 +08:00
[id="{page-id}-partial"]
2020-06-30 02:53:30 +08:00
`partial`::
2020-10-29 21:04:43 +08:00
(Optional, Boolean)
2020-06-30 02:53:30 +08:00
If `false`, the entire snapshot will fail if one or more indices included in the snapshot do not have all primary shards available. Defaults to `false`.
+
If `true`, allows taking a partial snapshot of indices with unavailable shards.
2021-08-20 20:29:16 +08:00
// end::snapshot-config[]
2021-08-23 09:18:51 +08:00
2021-08-20 20:29:16 +08:00
// Unset the attribute
:!page-id:
2020-06-30 02:53:30 +08:00
[[create-snapshot-api-example]]
==== {api-examples-title}
The following request takes a snapshot of `index_1` and `index_2`.
[source,console]
-----------------------------------
PUT /_snapshot/my_repository/snapshot_2?wait_for_completion=true
{
"indices": "index_1,index_2",
"ignore_unavailable": true,
"include_global_state": false,
"metadata": {
"taken_by": "user123",
"taken_because": "backup before upgrading"
}
}
-----------------------------------
The API returns the following response:
[source,console-result]
----
{
"snapshot": {
"snapshot": "snapshot_2",
"uuid": "vdRctLCxSketdKb54xw67g",
2021-06-24 22:58:33 +08:00
"repository": "my_repository",
2020-06-30 02:53:30 +08:00
"version_id": <version_id>,
"version": <version>,
"indices": [],
"data_streams": [],
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-12 02:55:14 +08:00
"feature_states": [],
2020-06-30 02:53:30 +08:00
"include_global_state": false,
"metadata": {
"taken_by": "user123",
"taken_because": "backup before upgrading"
},
"state": "SUCCESS",
"start_time": "2020-06-25T14:00:28.850Z",
"start_time_in_millis": 1593093628850,
"end_time": "2020-06-25T14:00:28.850Z",
"end_time_in_millis": 1593094752018,
"duration_in_millis": 0,
"failures": [],
"shards": {
"total": 0,
"failed": 0,
"successful": 0
}
}
}
----
// TESTRESPONSE[s/"uuid": "vdRctLCxSketdKb54xw67g"/"uuid": $body.snapshot.uuid/]
// TESTRESPONSE[s/"version_id": <version_id>/"version_id": $body.snapshot.version_id/]
// TESTRESPONSE[s/"version": <version>/"version": $body.snapshot.version/]
// TESTRESPONSE[s/"start_time": "2020-06-25T14:00:28.850Z"/"start_time": $body.snapshot.start_time/]
// TESTRESPONSE[s/"start_time_in_millis": 1593093628850/"start_time_in_millis": $body.snapshot.start_time_in_millis/]
// TESTRESPONSE[s/"end_time": "2020-06-25T14:00:28.850Z"/"end_time": $body.snapshot.end_time/]
// TESTRESPONSE[s/"end_time_in_millis": 1593094752018/"end_time_in_millis": $body.snapshot.end_time_in_millis/]
// TESTRESPONSE[s/"duration_in_millis": 0/"duration_in_millis": $body.snapshot.duration_in_millis/]