@@ -7,7 +7,9 @@ The Snapshot Lifecycle Management APIs are used to manage policies for the time
77and frequency of automatic snapshots. Snapshot Lifecycle Management is related
88to <<index-lifecycle-management,Index Lifecycle Management>>, however, instead
99of managing a lifecycle of actions that are performed on a single index, SLM
10- allows configuring policies spanning multiple indices.
10+ allows configuring policies spanning multiple indices. Snapshot Lifecycle
11+ Management can also perform deletion of older snapshots based on a configurable
12+ retention policy.
1113
1214SLM policy management is split into three different CRUD APIs, a way to put or update
1315policies, a way to retrieve policies, and a way to delete unwanted policies, as
@@ -62,7 +64,11 @@ PUT /_slm/policy/daily-snapshots
6264 "ignore_unavailable": false,
6365 "include_global_state": false
6466 },
65- "retention": {}
67+ "retention": { <6>
68+ "expire_after": "30d", <7>
69+ "min_count": 5, <8>
70+ "max_count": 50 <9>
71+ }
6672}
6773--------------------------------------------------
6874// TEST[setup:setup-repository]
@@ -72,6 +78,10 @@ PUT /_slm/policy/daily-snapshots
7278<3> Which repository to take the snapshot in
7379<4> Any extra snapshot configuration
7480<5> Which indices the snapshot should contain
81+ <6> Optional retention configuration
82+ <7> Keep snapshots for 30 days
83+ <8> Always keep at least 5 successful snapshots, even if they're more than 30 days old
84+ <9> Keep no more than 50 successful snapshots, even if they're less than 30 days old
7585
7686The top-level keys that the policy supports are described below:
7787
@@ -139,7 +149,11 @@ The output looks similar to the following:
139149 "ignore_unavailable": false,
140150 "include_global_state": false
141151 },
142- "retention": {}
152+ "retention": {
153+ "expire_after": "30d",
154+ "min_count": 5,
155+ "max_count": 50
156+ }
143157 },
144158 "stats": {
145159 "policy": "daily-snapshots",
@@ -229,7 +243,11 @@ Which, in this case shows an error because the index did not exist:
229243 "ignore_unavailable": false,
230244 "include_global_state": false
231245 },
232- "retention": {}
246+ "retention": {
247+ "expire_after": "30d",
248+ "min_count": 5,
249+ "max_count": 50
250+ }
233251 },
234252 "stats": {
235253 "policy": "daily-snapshots",
@@ -270,6 +288,11 @@ PUT /_slm/policy/daily-snapshots
270288 "indices": ["data-*", "important"],
271289 "ignore_unavailable": true,
272290 "include_global_state": false
291+ },
292+ "retention": {
293+ "expire_after": "30d",
294+ "min_count": 5,
295+ "max_count": 50
273296 }
274297}
275298--------------------------------------------------
@@ -318,7 +341,11 @@ Which now includes the successful snapshot information:
318341 "ignore_unavailable": true,
319342 "include_global_state": false
320343 },
321- "retention": {}
344+ "retention": {
345+ "expire_after": "30d",
346+ "min_count": 5,
347+ "max_count": 50
348+ }
322349 },
323350 "stats": {
324351 "policy": "daily-snapshots",
@@ -374,22 +401,14 @@ Which returns a response similar to:
374401 "retention_timed_out": 0,
375402 "retention_deletion_time": "1.4s",
376403 "retention_deletion_time_millis": 1404,
377- "policy_metrics": [
378- {
379- "policy": "daily-snapshots",
380- "snapshots_taken": 1,
381- "snapshots_failed": 1,
382- "snapshots_deleted": 0,
383- "snapshot_deletion_failures": 0
384- }
385- ],
404+ "policy_stats": [ ],
386405 "total_snapshots_taken": 1,
387406 "total_snapshots_failed": 1,
388407 "total_snapshots_deleted": 0,
389408 "total_snapshot_deletion_failures": 0
390409}
391410--------------------------------------------------
392- // TESTRESPONSE[s/runs": 13/runs": $body.retention_runs/ s/_failed": 0/_failed": $body.retention_failed/ s/_timed_out": 0/_timed_out": $body.retention_timed_out/ s/"1.4s"/$body.retention_deletion_time/ s/1404/$body.retention_deletion_time_millis/]
411+ // TESTRESPONSE[s/runs": 13/runs": $body.retention_runs/ s/_failed": 0/_failed": $body.retention_failed/ s/_timed_out": 0/_timed_out": $body.retention_timed_out/ s/"1.4s"/$body.retention_deletion_time/ s/1404/$body.retention_deletion_time_millis/ s/total_snapshots_taken": 1/total_snapshots_taken": $body.total_snapshots_taken/ s/total_snapshots_failed": 1/total_snapshots_failed": $body.total_snapshots_failed/ s/"policy_stats": [.*]/"policy_stats": $body.policy_stats/ ]
393412
394413[[slm-api-delete]]
395414=== Delete Snapshot Lifecycle Policy API
@@ -410,3 +429,29 @@ any currently ongoing snapshots or remove any previously taken snapshots.
410429DELETE /_slm/policy/daily-snapshots
411430--------------------------------------------------
412431// TEST[continued]
432+
433+ [[slm-api-execute-retention]]
434+ === Execute Snapshot Lifecycle Retention API
435+
436+ While Snapshot Lifecycle Management retention is usually invoked through the global cluster settings
437+ for its schedule, it can sometimes be useful to invoke a retention run to expunge expired snapshots
438+ immediately. This API allows you to run a one-off retention run.
439+
440+ ==== Example
441+
442+ To immediately start snapshot retention, use the following
443+
444+ [source,console]
445+ --------------------------------------------------
446+ POST /_slm/_execute_retention
447+ --------------------------------------------------
448+
449+ This API will immediately return, as retention will be run asynchronously in the background:
450+
451+ [source,console-result]
452+ --------------------------------------------------
453+ {
454+ "acknowledged": true
455+ }
456+ --------------------------------------------------
457+
0 commit comments