slm-put.asciidoc 4.2 KB

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