slm-put.asciidoc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. [[slm-api-put-policy]]
  2. === Create or update snapshot lifecycle policy API
  3. ++++
  4. <titleabbrev>Create or update policy</titleabbrev>
  5. ++++
  6. Creates or updates a snapshot lifecycle policy.
  7. [[slm-api-put-request]]
  8. ==== {api-request-title}
  9. `PUT /_slm/policy/<snapshot-lifecycle-policy-id>`
  10. [[slm-api-put-prereqs]]
  11. ==== {api-prereq-title}
  12. If the {es} {security-features} are enabled, you must have the
  13. `manage_slm` cluster privilege and the `manage` index privilege
  14. for any included indices to use this API.
  15. For more information, see <<security-privileges>>.
  16. [[slm-api-put-desc]]
  17. ==== {api-description-title}
  18. Use the create or update snapshot lifecycle policy API
  19. to create or update a snapshot lifecycle policy.
  20. If the policy already exists,
  21. this request increments the policy's version.
  22. Only the latest version of a policy is stored.
  23. [[slm-api-put-path-params]]
  24. ==== {api-path-parms-title}
  25. `<snapshot-lifecycle-policy-id>`::
  26. (Required, string)
  27. ID for the snapshot lifecycle policy
  28. you want to create or update.
  29. [[slm-api-put-query-params]]
  30. ==== {api-query-parms-title}
  31. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
  32. [role="child_attributes"]
  33. [[slm-api-put-request-body]]
  34. ==== {api-request-body-title}
  35. `config`::
  36. (Required, object)
  37. Configuration for each snapshot created by the policy.
  38. +
  39. .Properties of `config`
  40. [%collapsible%open]
  41. ====
  42. :page-id: put-slm-api
  43. include::{es-repo-dir}/snapshot-restore/apis/create-snapshot-api.asciidoc[tag=snapshot-config]
  44. :!page-id:
  45. ====
  46. `name`::
  47. (Required, string)
  48. Name automatically assigned to each snapshot created by the policy.
  49. <<date-math-index-names,Date math>> is supported.
  50. To prevent conflicting snapshot names, a UUID is automatically appended to each
  51. snapshot name.
  52. `repository`::
  53. (Required, string)
  54. Repository used to store snapshots created by this policy. This repository must
  55. exist prior to the policy's creation. You can create a repository using the
  56. <<modules-snapshots,snapshot repository API>>.
  57. [[slm-api-put-retention]]
  58. `retention`::
  59. (Optional, object)
  60. Retention rules used to retain and delete snapshots created by the policy.
  61. +
  62. .Properties of `retention`
  63. [%collapsible%open]
  64. ====
  65. `expire_after`::
  66. (Optional, <<time-units, time units>>)
  67. Time period after which a snapshot is considered expired and eligible for
  68. deletion. {slm-init} deletes expired snapshots based on the
  69. <<slm-retention-schedule,`slm.retention_schedule`>>.
  70. `max_count`::
  71. (Optional, integer)
  72. Maximum number of snapshots to retain, even if the snapshots have not yet
  73. expired. If the number of snapshots in the repository exceeds this limit, the
  74. policy retains the most recent snapshots and deletes older snapshots. This limit
  75. only includes snapshots with a <<get-snapshot-api-response-state,`state`>> of
  76. `SUCCESS`.
  77. +
  78. NOTE: The maximum number of snapshots in a repository should not exceed `200`. This ensures that the snapshot repository metadata does not
  79. grow to a size which might destabilize the master node. If the `max_count` setting is not set, this limit should be enforced by configuring
  80. other retention rules such that the repository size does not exceed `200` snapshots.
  81. `min_count`::
  82. (Optional, integer)
  83. Minimum number of snapshots to retain, even if the snapshots have expired.
  84. ====
  85. `schedule`::
  86. (Required, <<cron-expressions,Cron syntax>>)
  87. Periodic or absolute schedule at which the policy creates snapshots. {slm-init}
  88. applies `schedule` changes immediately.
  89. [[slm-api-put-example]]
  90. ==== {api-examples-title}
  91. Create a `daily-snapshots` lifecycle policy:
  92. [source,console]
  93. --------------------------------------------------
  94. PUT /_slm/policy/daily-snapshots
  95. {
  96. "schedule": "0 30 1 * * ?", <1>
  97. "name": "<daily-snap-{now/d}>", <2>
  98. "repository": "my_repository", <3>
  99. "config": { <4>
  100. "indices": ["data-*", "important"], <5>
  101. "ignore_unavailable": false,
  102. "include_global_state": false
  103. },
  104. "retention": { <6>
  105. "expire_after": "30d", <7>
  106. "min_count": 5, <8>
  107. "max_count": 50 <9>
  108. }
  109. }
  110. --------------------------------------------------
  111. // TEST[setup:setup-repository]
  112. <1> When the snapshot should be taken, in this case, 1:30am daily
  113. <2> The name each snapshot should be given
  114. <3> Which repository to take the snapshot in
  115. <4> Any extra snapshot configuration
  116. <5> Data streams and indices the snapshot should contain
  117. <6> Optional retention configuration
  118. <7> Keep snapshots for 30 days
  119. <8> Always keep at least 5 successful snapshots, even if they're more than 30 days old
  120. <9> Keep no more than 50 successful snapshots, even if they're less than 30 days old