slm-put.asciidoc 4.2 KB

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