原英文版地址: https://www.elastic.co/guide/en/elasticsearch/reference/7.7/slm-api-put-policy.html, 原文档版权归 www.elastic.co 所有
本地英文版地址: ../en/slm-api-put-policy.html

Put snapshot lifecycle policy APIedit

Creates or updates a snapshot lifecycle policy.

Requestedit

PUT /_slm/policy/<snapshot-lifecycle-policy-id>

Prerequisitesedit

If the Elasticsearch 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.

Descriptionedit

Use the put 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.

Path parametersedit

<snapshot-lifecycle-policy-id>
(Required, string) ID for the snapshot lifecycle policy you want to create or update.

Query parametersedit

master_timeout
(Optional, time units) Specifies the period of time to wait for a connection to the master node. If no response is received before the timeout expires, the request fails and returns an error. Defaults to 30s.
timeout
(Optional, time units) Specifies the period of time to wait for a response. If no response is received before the timeout expires, the request fails and returns an error. Defaults to 30s.

Request bodyedit

config

(Required, object) Configuration for each snapshot created by the policy.

Properties of config
ignore_unavailable
(Optional, boolean) If true, missing indices do not cause snapshot creation to fail and return an error. Defaults to false.
include_global_state
(Optional, boolean) If true, cluster states are included in snapshots. Defaults to false.
indices
(Optional, array of strings) Array of index names or wildcard pattern of index names included in snapshots. It supports date math expressions.
name
(Required, string) Name automatically assigned to each snapshot created by the policy. This value supports the same date math supported in index names. 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 repository API.
retention

(Optional, object) Retention rules used to retain and delete snapshots created by the policy.

Properties of retention
expire_after
(Optional, time units) Time period after which a snapshot is considered expired and eligible for deletion.
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.
min_count
(Optional, integer) Minimum number of snapshots to retain, even if the snapshots have expired.
schedule
(Required, Cron syntax) Periodic or absolute schedule at which the policy creates snapshots and deletes expired snapshots. Schedule changes to existing policies are applied immediately.

Examplesedit

Create a daily-snapshots lifecycle policy:

PUT /_slm/policy/daily-snapshots
{
  "schedule": "0 30 1 * * ?", 
  "name": "<daily-snap-{now/d}>", 
  "repository": "my_repository", 
  "config": { 
    "indices": ["data-*", "important"], 
    "ignore_unavailable": false,
    "include_global_state": false
  },
  "retention": { 
    "expire_after": "30d", 
    "min_count": 5, 
    "max_count": 50 
  }
}

When the snapshot should be taken, in this case, 1:30am daily

The name each snapshot should be given

Which repository to take the snapshot in

Any extra snapshot configuration

Which indices the snapshot should contain

Optional retention configuration

Keep snapshots for 30 days

Always keep at least 5 successful snapshots, even if they’re more than 30 days old

Keep no more than 50 successful snapshots, even if they’re less than 30 days old