elasticsearch/docs/reference/slm/apis/slm-put.asciidoc
Liam Thompson 33a71e3289
[DOCS] Refactor book-scoped variables in docs/reference/index.asciidoc (#107413)
* Remove `es-test-dir` book-scoped variable

* Remove `plugins-examples-dir` book-scoped variable

* Remove `:dependencies-dir:` and `:xes-repo-dir:` book-scoped variables

- In `index.asciidoc`, two variables (`:dependencies-dir:` and `:xes-repo-dir:`) were removed.
- In `sql/index.asciidoc`, the `:sql-tests:` path was updated to fuller path
- In `esql/index.asciidoc`, the `:esql-tests:` path was updated idem

* Replace `es-repo-dir` with `es-ref-dir`

* Move `:include-xpack: true` to few files that use it, remove from index.asciidoc
2024-04-17 14:37:07 +02:00

141 lines
No EOL
4.1 KiB
Text

[[slm-api-put-policy]]
=== Create or update snapshot lifecycle policy API
++++
<titleabbrev>Create or update policy</titleabbrev>
++++
Creates or updates a snapshot lifecycle policy.
[[slm-api-put-request]]
==== {api-request-title}
`PUT /_slm/policy/<snapshot-lifecycle-policy-id>`
[[slm-api-put-prereqs]]
==== {api-prereq-title}
If the {es} {security-features} are enabled, you must have the
`manage_slm` cluster privilege and the `manage` index privilege
for any included indices to use this API.
For more information, see <<security-privileges>>.
[[slm-api-put-desc]]
==== {api-description-title}
Use the create or update snapshot lifecycle policy API
to create or update a snapshot lifecycle policy.
If the policy already exists,
this request increments the policy's version.
Only the latest version of a policy is stored.
[[slm-api-put-path-params]]
==== {api-path-parms-title}
`<snapshot-lifecycle-policy-id>`::
(Required, string)
ID for the snapshot lifecycle policy
you want to create or update.
[[slm-api-put-query-params]]
==== {api-query-parms-title}
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
[role="child_attributes"]
[[slm-api-put-request-body]]
==== {api-request-body-title}
`config`::
(Required, object)
Configuration for each snapshot created by the policy.
+
.Properties of `config`
[%collapsible%open]
====
:page-id: put-slm-api
include::{es-ref-dir}/snapshot-restore/apis/create-snapshot-api.asciidoc[tag=snapshot-config]
:!page-id:
====
`name`::
(Required, string)
Name automatically assigned to each snapshot created by the policy.
<<api-date-math-index-names,Date math>> is supported.
To prevent conflicting snapshot names, a UUID is automatically appended to each
snapshot name.
`repository`::
(Required, string)
Repository used to store snapshots created by this policy. This repository must
exist prior to the policy's creation. You can create a repository using the
<<snapshot-restore,snapshot repository API>>.
[[slm-api-put-retention]]
`retention`::
(Optional, object)
Retention rules used to retain and delete snapshots created by the policy.
+
.Properties of `retention`
[%collapsible%open]
====
`expire_after`::
(Optional, <<time-units, time units>>)
Time period after which a snapshot is considered expired and eligible for
deletion. {slm-init} deletes expired snapshots based on the
<<slm-retention-schedule,`slm.retention_schedule`>>.
`max_count`::
(Optional, integer)
Maximum number of snapshots to retain, even if the snapshots have not yet
expired. If the number of snapshots in the repository exceeds this limit, the
policy retains the most recent snapshots and deletes older snapshots. This limit
only includes snapshots with a <<get-snapshot-api-response-state,`state`>> of
`SUCCESS`.
`min_count`::
(Optional, integer)
Minimum number of snapshots to retain, even if the snapshots have expired.
====
`schedule`::
(Required, <<api-cron-expressions,Cron syntax>>)
Periodic or absolute schedule at which the policy creates snapshots. {slm-init}
applies `schedule` changes immediately.
[[slm-api-put-example]]
==== {api-examples-title}
Create a `daily-snapshots` lifecycle policy:
[source,console]
--------------------------------------------------
PUT /_slm/policy/daily-snapshots
{
"schedule": "0 30 1 * * ?", <1>
"name": "<daily-snap-{now/d}>", <2>
"repository": "my_repository", <3>
"config": { <4>
"indices": ["data-*", "important"], <5>
"ignore_unavailable": false,
"include_global_state": false
},
"retention": { <6>
"expire_after": "30d", <7>
"min_count": 5, <8>
"max_count": 50 <9>
}
}
--------------------------------------------------
// TEST[setup:setup-repository]
<1> When the snapshot should be taken, in this case, 1:30am daily
<2> The name each snapshot should be given
<3> Which repository to take the snapshot in
<4> Any extra snapshot configuration
<5> Data streams and indices the snapshot should contain
<6> Optional retention configuration
<7> Keep snapshots for 30 days
<8> Always keep at least 5 successful snapshots, even if they're more than 30 days old
<9> Keep no more than 50 successful snapshots, even if they're less than 30 days old