slm-retention.asciidoc 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[slm-retention]]
  4. === Snapshot retention
  5. You can include a retention policy in an {slm-init} policy to automatically delete old snapshots.
  6. Retention runs as a cluster-level task and is not associated with a particular policy's schedule.
  7. The retention criteria are evaluated as part of the retention task, not when the policy executes.
  8. For the retention task to automatically delete snapshots,
  9. you need to include a <<slm-api-put-retention,`retention`>> object in your {slm-init} policy.
  10. To control when the retention task runs, configure
  11. <<slm-retention-schedule,`slm.retention_schedule`>> in the cluster settings.
  12. You can define the schedule as a periodic or absolute <<schedule-cron, cron schedule>>.
  13. The <<slm-retention-duration,`slm.retention_duration`>> setting limits how long
  14. {slm-init} should spend deleting old snapshots.
  15. You can update the schedule and duration dynamically with the
  16. <<cluster-update-settings, update settings>> API.
  17. You can run the retention task manually with the
  18. <<slm-api-execute-retention, execute retention >> API.
  19. The retention task only considers snapshots initiated through {slm-init} policies,
  20. either according to the policy schedule or through the
  21. <<slm-api-execute-lifecycle, execute lifecycle>> API.
  22. Manual snapshots are ignored and don't count toward the retention limits.
  23. To retrieve information about the snapshot retention task history,
  24. use the <<slm-api-get-stats, get stats>> API:
  25. ////
  26. [source,console]
  27. --------------------------------------------------
  28. PUT /_slm/policy/daily-snapshots
  29. {
  30. "schedule": "0 30 1 * * ?",
  31. "name": "<daily-snap-{now/d}>",
  32. "repository": "my_repository",
  33. "retention": { <1>
  34. "expire_after": "30d", <2>
  35. "min_count": 5, <3>
  36. "max_count": 50 <4>
  37. }
  38. }
  39. --------------------------------------------------
  40. // TEST[setup:setup-repository]
  41. <1> Optional retention configuration
  42. <2> Keep snapshots for 30 days
  43. <3> Always keep at least 5 successful snapshots
  44. <4> Keep no more than 50 successful snapshots
  45. ////
  46. [source,console]
  47. --------------------------------------------------
  48. GET /_slm/stats
  49. --------------------------------------------------
  50. // TEST[continued]
  51. The response includes the following statistics:
  52. [source,js]
  53. --------------------------------------------------
  54. {
  55. "retention_runs": 13, <1>
  56. "retention_failed": 0, <2>
  57. "retention_timed_out": 0, <3>
  58. "retention_deletion_time": "1.4s", <4>
  59. "retention_deletion_time_millis": 1404,
  60. "policy_stats": [
  61. {
  62. "policy": "daily-snapshots",
  63. "snapshots_taken": 1,
  64. "snapshots_failed": 1,
  65. "snapshots_deleted": 0, <5>
  66. "snapshot_deletion_failures": 0 <6>
  67. }
  68. ],
  69. "total_snapshots_taken": 1,
  70. "total_snapshots_failed": 1,
  71. "total_snapshots_deleted": 0, <7>
  72. "total_snapshot_deletion_failures": 0 <8>
  73. }
  74. --------------------------------------------------
  75. // TESTRESPONSE[skip:this is not actually running retention]
  76. <1> Number of times retention has been run
  77. <2> Number of times retention failed while running
  78. <3> Number of times retention hit the `slm.retention_duration` time limit and had to stop before deleting all eligible snapshots
  79. <4> Total time spent deleting snapshots by the retention process
  80. <5> Number of snapshots created by the "daily-snapshots" policy that have been deleted
  81. <6> Number of snapshots that failed to be deleted
  82. <7> Total number of snapshots deleted across all policies
  83. <8> Total number of snapshot deletion failures across all policies