Create snapshot API
editCreate snapshot API
editTakes a snapshot of a cluster or specified data streams and indices.
resp = client.snapshot.create(
repository="my_repository",
snapshot="my_snapshot",
)
print(resp)
response = client.snapshot.create( repository: 'my_repository', snapshot: 'my_snapshot' ) puts response
const response = await client.snapshot.create({
repository: "my_repository",
snapshot: "my_snapshot",
});
console.log(response);
PUT /_snapshot/my_repository/my_snapshot
Prerequisites
edit-
If the Elasticsearch security features are enabled, you must have the
create_snapshotormanagecluster privilege to use this API.
Path parameters
edit-
<repository> - (Required, string) Name of the snapshot repository.
-
<snapshot> - (Required, string) Name of the snapshot. Supports date math. Must be unique within the snapshot repository.
Query parameters
edit-
master_timeout -
(Optional, time units)
Period to wait for the master node. If the master node is not available before
the timeout expires, the request fails and returns an error. Defaults to
30s. Can also be set to-1to indicate that the request should never timeout. -
wait_for_completion -
(Optional, Boolean) If
true, the request returns a response when the snapshot is complete. Iffalse, the request returns a response when the snapshot initializes. Defaults tofalse.
Request body
edit-
expand_wildcards -
(Optional, string) Determines how wildcard patterns in the
indicesparameter match data streams and indices. Supports comma-separated values, such asopen,hidden. Defaults toall. Valid values are:-
all - Match any data stream or index, including closed and hidden ones.
-
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.
-
-
ignore_unavailable -
(Optional, Boolean)
If
false, the snapshot fails if any data stream or index inindicesis missing. Iftrue, the snapshot ignores missing data streams and indices. Defaults tofalse. -
include_global_state -
(Optional, Boolean) If
true, include the cluster state in the snapshot. Defaults totrue. The cluster state includes:- Persistent cluster settings
- Index templates
- Legacy index templates
- Ingest pipelines
- ILM policies
- Stored scripts
- For snapshots taken after 7.12.0, feature states
-
indices -
(Optional, string or array of strings) Comma-separated list of data streams and indices to include in the snapshot. Supports multi-target syntax. Defaults to an empty array (
[]), which includes all regular data streams and regular indices. To exclude all data streams and indices, use-*.You can’t use this parameter to include or exclude system indices or system data streams from a snapshot. Use
feature_statesinstead.
-
feature_states -
(Optional, array of strings) Feature states to include in the snapshot. To get a list of possible values and their descriptions, use the get features API.
If
include_global_stateistrue, the snapshot includes all feature states by default. Ifinclude_global_stateisfalse, the snapshot includes no feature states by default.Note that specifying an empty array will result in the default behavior. To exclude all feature states, regardless of the
include_global_statevalue, specify an array with only the valuenone(["none"]). -
metadata - (Optional, object) 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.
Examples
editThe following request takes a snapshot of index_1 and index_2.
resp = client.snapshot.create(
repository="my_repository",
snapshot="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"
},
)
print(resp)
response = client.snapshot.create(
repository: 'my_repository',
snapshot: 'snapshot_2',
wait_for_completion: true,
body: {
indices: 'index_1,index_2',
ignore_unavailable: true,
include_global_state: false,
metadata: {
taken_by: 'user123',
taken_because: 'backup before upgrading'
}
}
)
puts response
const response = await client.snapshot.create({
repository: "my_repository",
snapshot: "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",
},
});
console.log(response);
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:
{
"snapshot": {
"snapshot": "snapshot_2",
"uuid": "vdRctLCxSketdKb54xw67g",
"repository": "my_repository",
"version_id": <version_id>,
"version": <version>,
"indices": [],
"data_streams": [],
"feature_states": [],
"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
}
}
}