slm-put.asciidoc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. [[slm-api-put-policy]]
  2. === Put snapshot lifecycle policy API
  3. ++++
  4. <titleabbrev>Put 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 put 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.
  78. `max_count`::
  79. (Optional, integer)
  80. Maximum number of snapshots to retain, even if the snapshots have not yet
  81. expired. If the number of snapshots in the repository exceeds this limit, the
  82. policy retains the most recent snapshots and deletes older snapshots.
  83. +
  84. NOTE: The maximum number of snapshots in a repository should not exceed `200`. This ensures that the snapshot repository metadata does not
  85. 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
  86. other retention rules such that the repository size does not exceed `200` snapshots.
  87. `min_count`::
  88. (Optional, integer)
  89. Minimum number of snapshots to retain, even if the snapshots have expired.
  90. ====
  91. `schedule`::
  92. (Required, <<cron-expressions,Cron syntax>>)
  93. Periodic or absolute schedule at which the policy creates snapshots and deletes
  94. expired snapshots. Schedule changes to existing policies are applied immediately.
  95. [[slm-api-put-example]]
  96. ==== {api-examples-title}
  97. Create a `daily-snapshots` lifecycle policy:
  98. [source,console]
  99. --------------------------------------------------
  100. PUT /_slm/policy/daily-snapshots
  101. {
  102. "schedule": "0 30 1 * * ?", <1>
  103. "name": "<daily-snap-{now/d}>", <2>
  104. "repository": "my_repository", <3>
  105. "config": { <4>
  106. "indices": ["data-*", "important"], <5>
  107. "ignore_unavailable": false,
  108. "include_global_state": false
  109. },
  110. "retention": { <6>
  111. "expire_after": "30d", <7>
  112. "min_count": 5, <8>
  113. "max_count": 50 <9>
  114. }
  115. }
  116. --------------------------------------------------
  117. // TEST[setup:setup-repository]
  118. <1> When the snapshot should be taken, in this case, 1:30am daily
  119. <2> The name each snapshot should be given
  120. <3> Which repository to take the snapshot in
  121. <4> Any extra snapshot configuration
  122. <5> Data streams and indices the snapshot should contain
  123. <6> Optional retention configuration
  124. <7> Keep snapshots for 30 days
  125. <8> Always keep at least 5 successful snapshots, even if they're more than 30 days old
  126. <9> Keep no more than 50 successful snapshots, even if they're less than 30 days old