The _slm API automates recurring Elasticsearch snapshots by storing lifecycle policies in the cluster. A policy selects the repository and indexes to back up, defines when snapshots run, and controls retention. A registered snapshot repository is required before creating a policy. section 14.4.6
Nightly movie-index backups
PUT _slm/policy/prod_cluster_daily_backups creates a policy for snapshots at midnight. The name <prod_daily_backups-{now/d}> uses date math to generate a date-specific snapshot name; the cron expression runs at midnight; the repository stores the snapshot; the index patterns select movie and review indexes; and the seven-day retention setting expires older snapshots. To trigger the policy immediately, use POST _slm/policy/prod_cluster_daily_backups/_execute. section 14.4.6
Listing 14.11 Creating a policy for scheduled snapshots
PUT _slm/policy/prod_cluster_daily_backups #1
{
"name":"<prod_daily_backups-{now/d}>", #2
"schedule": "0 0 0 * * ?", #3
"repository": "es_cluster_snapshot_repository", #4
"config": {
"indices":["*movies*", "*reviews*"], #5
"include_global_state": false #6
},
"retention":{
"Expire_after":"7d" #7
}
}
Use the complete REST listing to inspect the policy name, schedule, repository, index patterns, global-state choice, and retention configuration together. section 14.4.6
