slm-put.asciidoc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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::{docdir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
  32. [[slm-api-put-request-body]]
  33. ==== {api-request-body-title}
  34. `schedule`::
  35. (Required, <<schedule-cron,Cron scheduler configuration>>)
  36. Periodic or absolute schedule
  37. at which the policy creates snapshots
  38. and deletes expired snapshots.
  39. +
  40. Schedule changes to existing policies
  41. are applied immediately.
  42. `name`::
  43. +
  44. --
  45. (Required, string)
  46. Name automatically assigned to each snapshot
  47. created by the policy.
  48. This value supports the same <<date-math-index-names,date math>>
  49. supported in index names.
  50. To prevent conflicting snapshot names,
  51. a UUID is automatically appended to each snapshot name.
  52. --
  53. `repository`::
  54. +
  55. --
  56. (Required, string)
  57. Repository used to store snapshots
  58. created by this policy.
  59. This repository must exist prior to the policy's creation.
  60. You can create a repository
  61. using the <<modules-snapshots,snapshot repository API>>.
  62. --
  63. `config`::
  64. +
  65. --
  66. (Required, object)
  67. Configuration for each snapshot
  68. created by the policy.
  69. Parameters include:
  70. `indices`::
  71. (Optional, array of strings)
  72. Array of index names or wildcard pattern of index names
  73. included in snapshots.
  74. `ignore_unavailable`::
  75. (Optional, boolean)
  76. If `true`,
  77. missing indices do *not* cause snapshot creation to fail
  78. and return an error.
  79. Defaults to `false`.
  80. `include_global_state`::
  81. (Optional, boolean)
  82. If `true`,
  83. cluster states are included in snapshots.
  84. Defaults to `false`.
  85. --
  86. `retention`::
  87. +
  88. --
  89. (Optional, object)
  90. Retention rules used to retain
  91. and delete snapshots
  92. created by the policy.
  93. Parameters include:
  94. `expire_after`::
  95. (Optional, <<time-units, time units>>)
  96. Time period after which
  97. a snapshot is considered expired
  98. and eligible for deletion.
  99. `max_count`::
  100. (Optional, integer)
  101. Maximum number of snapshots to retain,
  102. even if the snapshots have not yet expired.
  103. +
  104. If the number of snapshots in the repository exceeds this limit,
  105. the policy retains the most recent snapshots
  106. and deletes older snapshots.
  107. `min_count`::
  108. (Optional, integer)
  109. Minimum number of snapshots to retain,
  110. even if the snapshots have expired.
  111. --
  112. [[slm-api-put-example]]
  113. ==== {api-examples-title}
  114. Create a `daily-snapshots` lifecycle policy:
  115. [source,console]
  116. --------------------------------------------------
  117. PUT /_slm/policy/daily-snapshots
  118. {
  119. "schedule": "0 30 1 * * ?", <1>
  120. "name": "<daily-snap-{now/d}>", <2>
  121. "repository": "my_repository", <3>
  122. "config": { <4>
  123. "indices": ["data-*", "important"], <5>
  124. "ignore_unavailable": false,
  125. "include_global_state": false
  126. },
  127. "retention": { <6>
  128. "expire_after": "30d", <7>
  129. "min_count": 5, <8>
  130. "max_count": 50 <9>
  131. }
  132. }
  133. --------------------------------------------------
  134. // TEST[setup:setup-repository]
  135. <1> When the snapshot should be taken, in this case, 1:30am daily
  136. <2> The name each snapshot should be given
  137. <3> Which repository to take the snapshot in
  138. <4> Any extra snapshot configuration
  139. <5> Which indices the snapshot should contain
  140. <6> Optional retention configuration
  141. <7> Keep snapshots for 30 days
  142. <8> Always keep at least 5 successful snapshots, even if they're more than 30 days old
  143. <9> Keep no more than 50 successful snapshots, even if they're less than 30 days old