slm-put.asciidoc 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. `ignore_unavailable`::
  43. (Optional, Boolean)
  44. If `true`, missing data streams or indices do *not* cause snapshot creation to fail and return
  45. an error. Defaults to `false`.
  46. `include_global_state`::
  47. (Optional, Boolean)
  48. If `true`, cluster states are included in snapshots. Defaults to `false`.
  49. `indices`::
  50. (Optional, array of strings)
  51. Array of data streams and indices to include in snapshots.
  52. <<date-math-index-names,Date math>> and wildcard (`*`) expressions are
  53. supported.
  54. ====
  55. `name`::
  56. (Required, string)
  57. Name automatically assigned to each snapshot created by the policy.
  58. <<date-math-index-names,Date math>> is supported.
  59. To prevent conflicting snapshot names, a UUID is automatically appended to each
  60. snapshot name.
  61. `repository`::
  62. (Required, string)
  63. Repository used to store snapshots created by this policy. This repository must
  64. exist prior to the policy's creation. You can create a repository using the
  65. <<modules-snapshots,snapshot repository API>>.
  66. [[slm-api-put-retention]]
  67. `retention`::
  68. (Optional, object)
  69. Retention rules used to retain and delete snapshots created by the policy.
  70. +
  71. .Properties of `retention`
  72. [%collapsible%open]
  73. ====
  74. `expire_after`::
  75. (Optional, <<time-units, time units>>)
  76. Time period after which a snapshot is considered expired and eligible for
  77. deletion. {slm-init} deletes expired snapshots based on the
  78. <<slm-retention-schedule,`slm.retention_schedule`>>.
  79. `max_count`::
  80. (Optional, integer)
  81. Maximum number of snapshots to retain, even if the snapshots have not yet
  82. expired. If the number of snapshots in the repository exceeds this limit, the
  83. policy retains the most recent snapshots and deletes older snapshots.
  84. +
  85. NOTE: The maximum number of snapshots in a repository should not exceed `200`. This ensures that the snapshot repository metadata does not
  86. 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
  87. other retention rules such that the repository size does not exceed `200` snapshots.
  88. `min_count`::
  89. (Optional, integer)
  90. Minimum number of snapshots to retain, even if the snapshots have expired.
  91. ====
  92. `schedule`::
  93. (Required, <<cron-expressions,Cron syntax>>)
  94. Periodic or absolute schedule at which the policy creates snapshots. {slm-init}
  95. applies `schedule` changes immediately.
  96. [[slm-api-put-example]]
  97. ==== {api-examples-title}
  98. Create a `daily-snapshots` lifecycle policy:
  99. [source,console]
  100. --------------------------------------------------
  101. PUT /_slm/policy/daily-snapshots
  102. {
  103. "schedule": "0 30 1 * * ?", <1>
  104. "name": "<daily-snap-{now/d}>", <2>
  105. "repository": "my_repository", <3>
  106. "config": { <4>
  107. "indices": ["data-*", "important"], <5>
  108. "ignore_unavailable": false,
  109. "include_global_state": false
  110. },
  111. "retention": { <6>
  112. "expire_after": "30d", <7>
  113. "min_count": 5, <8>
  114. "max_count": 50 <9>
  115. }
  116. }
  117. --------------------------------------------------
  118. // TEST[setup:setup-repository]
  119. <1> When the snapshot should be taken, in this case, 1:30am daily
  120. <2> The name each snapshot should be given
  121. <3> Which repository to take the snapshot in
  122. <4> Any extra snapshot configuration
  123. <5> Data streams and indices the snapshot should contain
  124. <6> Optional retention configuration
  125. <7> Keep snapshots for 30 days
  126. <8> Always keep at least 5 successful snapshots, even if they're more than 30 days old
  127. <9> Keep no more than 50 successful snapshots, even if they're less than 30 days old