slm-api.asciidoc 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[snapshot-lifecycle-management-api]]
  4. == Snapshot lifecycle management API
  5. The Snapshot Lifecycle Management APIs are used to manage policies for the time
  6. and frequency of automatic snapshots. Snapshot Lifecycle Management is related
  7. to <<index-lifecycle-management,Index Lifecycle Management>>, however, instead
  8. of managing a lifecycle of actions that are performed on a single index, SLM
  9. allows configuring policies spanning multiple indices. Snapshot Lifecycle
  10. Management can also perform deletion of older snapshots based on a configurable
  11. retention policy.
  12. SLM policy management is split into three different CRUD APIs, a way to put or update
  13. policies, a way to retrieve policies, and a way to delete unwanted policies, as
  14. well as a separate API for immediately invoking a snapshot based on a policy.
  15. SLM can be stopped temporarily and restarted using the <<slm-stop,Stop SLM>> and
  16. <<slm-start,Start SLM>> APIs. To disable SLM's functionality entirely, set the
  17. cluster setting `xpack.slm.enabled` to `false` in elasticsearch.yml.
  18. [[slm-api-put]]
  19. === Put snapshot lifecycle policy API
  20. ++++
  21. <titleabbrev>Put snapshot lifecycle policy</titleabbrev>
  22. ++++
  23. Creates or updates a snapshot lifecycle policy.
  24. [[slm-api-put-request]]
  25. ==== {api-request-title}
  26. `PUT /_slm/policy/<snapshot-lifecycle-policy-id>`
  27. [[slm-api-put-prereqs]]
  28. ==== {api-prereq-title}
  29. If you use {es} {security-features},
  30. you must have:
  31. * `manage_slm` <<privileges-list-cluster,cluster privileges>>
  32. * `manage` <<privileges-list-indices,index privileges>> for any included indices
  33. {slm-cap} operations are executed
  34. as the user that last created or updated the policy.
  35. For more information,
  36. see <<security-privileges>>.
  37. [[slm-api-put-desc]]
  38. ==== {api-description-title}
  39. Use the put snapshot lifecycle policy API
  40. to create or update a snapshot lifecycle policy.
  41. If the policy already exists,
  42. this request increments the policy's version.
  43. Only the latest version of the policy is stored.
  44. [[slm-api-put-path-params]]
  45. ==== {api-path-parms-title}
  46. `<snapshot-lifecycle-policy-id>`::
  47. (Required, string)
  48. ID for the snapshot lifecycle policy
  49. you want to create or update.
  50. [[slm-api-put-query-params]]
  51. ==== {api-query-parms-title}
  52. include::{docdir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
  53. [[slm-api-put-request-body]]
  54. ==== {api-request-body-title}
  55. `schedule`::
  56. (Required, <<schedule-cron,Cron scheduler configuration>>)
  57. Periodic or absolute schedule
  58. at which the policy creates snapshots
  59. and deletes expired snapshots.
  60. +
  61. Schedule changes to existing policies
  62. are applied immediately.
  63. `name`::
  64. +
  65. --
  66. (Required, string)
  67. Name automatically assigned to each snapshot
  68. created by the policy.
  69. This value supports the same <<date-math-index-names,date math>>
  70. supported in index names.
  71. To prevent conflicting snapshot names,
  72. a UUID is automatically appended to each snapshot name.
  73. --
  74. `repository`::
  75. +
  76. --
  77. (Required, string)
  78. Repository used to store snapshots
  79. created by this policy.
  80. This repository must exist prior to the policy's creation.
  81. You can create a repository
  82. using the <<modules-snapshots,snapshot repository API>>.
  83. --
  84. `config`::
  85. +
  86. --
  87. (Required, object)
  88. Configuration for each snapshot
  89. created by the policy.
  90. Parameters include:
  91. `indices`::
  92. (Optional, array of strings)
  93. Array of index names or wildcard pattern of index names
  94. included in snapshots.
  95. `ignore_unavailable`::
  96. (Optional, boolean)
  97. If `true`,
  98. missing indices do *not* cause snapshot creation to fail
  99. and return an error.
  100. Defaults to `false`.
  101. `include_global_state`::
  102. (Optional, boolean)
  103. If `true`,
  104. cluster states are included in snapshots.
  105. Defaults to `false`.
  106. --
  107. `retention`::
  108. +
  109. --
  110. (Optional, object)
  111. Retention rules used to retain
  112. and delete snapshots
  113. created by the policy.
  114. Parameters include:
  115. `expire_after`::
  116. (Optional, <<time-units, time units>>)
  117. Time period after which
  118. a snapshot is considered expired
  119. and eligible for deletion.
  120. `max_count`::
  121. (Optional, integer)
  122. Maximum number of snapshots to retain,
  123. even if the snapshots have not yet expired.
  124. +
  125. If the number of snapshots in the repository exceeds this limit,
  126. the policy retains the most recent snapshots
  127. and deletes older snapshots.
  128. `min_count`::
  129. (Optional, integer)
  130. Minimum number of snapshots to retain,
  131. even if the snapshots have expired.
  132. --
  133. [[slm-api-put-example]]
  134. ==== {api-examples-title}
  135. The following request creates a snapshot lifecycle policy
  136. with an ID of `daily-snapshots`:
  137. [source,console]
  138. --------------------------------------------------
  139. PUT /_slm/policy/daily-snapshots
  140. {
  141. "schedule": "0 30 1 * * ?", <1>
  142. "name": "<daily-snap-{now/d}>", <2>
  143. "repository": "my_repository", <3>
  144. "config": { <4>
  145. "indices": ["data-*", "important"], <5>
  146. "ignore_unavailable": false,
  147. "include_global_state": false
  148. },
  149. "retention": { <6>
  150. "expire_after": "30d", <7>
  151. "min_count": 5, <8>
  152. "max_count": 50 <9>
  153. }
  154. }
  155. --------------------------------------------------
  156. // TEST[setup:setup-repository]
  157. <1> When the snapshot should be taken, in this case, 1:30am daily
  158. <2> The name each snapshot should be given
  159. <3> Which repository to take the snapshot in
  160. <4> Any extra snapshot configuration
  161. <5> Which indices the snapshot should contain
  162. <6> Optional retention configuration
  163. <7> Keep snapshots for 30 days
  164. <8> Always keep at least 5 successful snapshots, even if they're more than 30 days old
  165. <9> Keep no more than 50 successful snapshots, even if they're less than 30 days old
  166. [[slm-api-get]]
  167. === Get snapshot lifecycle policy API
  168. ++++
  169. <titleabbrev>Get snapshot lifecycle policy</titleabbrev>
  170. ++++
  171. Returns information
  172. about one or more snapshot lifecycle policies.
  173. [[slm-api-get-request]]
  174. ==== {api-request-title}
  175. `GET /_slm/policy/<snapshot-lifecycle-policy-id>`
  176. `GET /_slm/policy/`
  177. [[slm-api-get-desc]]
  178. ==== {api-description-title}
  179. Use the snapshot lifecycle policy API
  180. to retrieve information
  181. about one or more snapshot lifecycle policies.
  182. The API response also includes information
  183. about the latest successful and failed attempts
  184. to create automatic snapshots.
  185. [[slm-api-get-path-params]]
  186. ==== {api-path-parms-title}
  187. `<snapshot-lifecycle-policy-id>`::
  188. (Optional, string)
  189. Comma-separated list of snapshot lifecycle policy IDs
  190. to retrieve.
  191. [[slm-api-get-example]]
  192. ==== {api-examples-title}
  193. [[slm-api-get-specific-ex]]
  194. ===== Get a specific policy
  195. [source,console]
  196. --------------------------------------------------
  197. GET /_slm/policy/daily-snapshots?human
  198. --------------------------------------------------
  199. // TEST[continued]
  200. The API returns the following response:
  201. [source,console-result]
  202. --------------------------------------------------
  203. {
  204. "daily-snapshots" : {
  205. "version": 1, <1>
  206. "modified_date": "2019-04-23T01:30:00.000Z", <2>
  207. "modified_date_millis": 1556048137314,
  208. "policy" : {
  209. "schedule": "0 30 1 * * ?",
  210. "name": "<daily-snap-{now/d}>",
  211. "repository": "my_repository",
  212. "config": {
  213. "indices": ["data-*", "important"],
  214. "ignore_unavailable": false,
  215. "include_global_state": false
  216. },
  217. "retention": {
  218. "expire_after": "30d",
  219. "min_count": 5,
  220. "max_count": 50
  221. }
  222. },
  223. "stats": {
  224. "policy": "daily-snapshots",
  225. "snapshots_taken": 0,
  226. "snapshots_failed": 0,
  227. "snapshots_deleted": 0,
  228. "snapshot_deletion_failures": 0
  229. },
  230. "next_execution": "2019-04-24T01:30:00.000Z", <3>
  231. "next_execution_millis": 1556048160000
  232. }
  233. }
  234. --------------------------------------------------
  235. // TESTRESPONSE[s/"modified_date": "2019-04-23T01:30:00.000Z"/"modified_date": $body.daily-snapshots.modified_date/ s/"modified_date_millis": 1556048137314/"modified_date_millis": $body.daily-snapshots.modified_date_millis/ s/"next_execution": "2019-04-24T01:30:00.000Z"/"next_execution": $body.daily-snapshots.next_execution/ s/"next_execution_millis": 1556048160000/"next_execution_millis": $body.daily-snapshots.next_execution_millis/]
  236. <1> The version of the snapshot policy, only the latest version is stored and incremented when the policy is updated
  237. <2> The last time this policy was modified.
  238. <3> The next time this policy will be executed.
  239. [[slm-api-get-all-ex]]
  240. ===== Get all policies
  241. [source,console]
  242. --------------------------------------------------
  243. GET /_slm/policy
  244. --------------------------------------------------
  245. // TEST[continued]
  246. [[slm-api-execute]]
  247. === Execute snapshot lifecycle policy API
  248. ++++
  249. <titleabbrev>Execute snapshot lifecycle policy</titleabbrev>
  250. ++++
  251. Executes a snapshot lifecycle policy, immediately creating a snapshot
  252. without waiting for the scheduled creation time.
  253. [[slm-api-execute-request]]
  254. ==== {api-request-title}
  255. `PUT /_slm/policy/<snapshot-lifecycle-policy-id>/_execute`
  256. [[slm-api-execute-desc]]
  257. ==== {api-description-title}
  258. Sometimes it can be useful to immediately execute a snapshot based on policy,
  259. perhaps before an upgrade or before performing other maintenance on indices. The
  260. execute snapshot policy API allows you to perform a snapshot immediately without
  261. waiting for a policy's scheduled invocation.
  262. [[slm-api-execute-path-params]]
  263. ==== {api-path-parms-title}
  264. `<snapshot-lifecycle-policy-id>`::
  265. (Required, string)
  266. ID of the snapshot lifecycle policy to execute.
  267. [[slm-api-execute-example]]
  268. ==== {api-examples-title}
  269. To take an immediate snapshot using a policy, use the following request:
  270. [source,console]
  271. --------------------------------------------------
  272. POST /_slm/policy/daily-snapshots/_execute
  273. --------------------------------------------------
  274. // TEST[skip:we can't easily handle snapshots from docs tests]
  275. This API returns the following response with the generated snapshot name:
  276. [source,console-result]
  277. --------------------------------------------------
  278. {
  279. "snapshot_name": "daily-snap-2019.04.24-gwrqoo2xtea3q57vvg0uea"
  280. }
  281. --------------------------------------------------
  282. // TESTRESPONSE[skip:we can't handle snapshots from docs tests]
  283. The snapshot will be taken in the background, you can use the
  284. <<modules-snapshots,snapshot APIs>> to monitor the status of the snapshot.
  285. Once a snapshot has been kicked off, you can see the latest successful or failed
  286. snapshot using the get snapshot lifecycle policy API:
  287. [source,console]
  288. --------------------------------------------------
  289. GET /_slm/policy/daily-snapshots?human
  290. --------------------------------------------------
  291. // TEST[skip:we already tested get policy above, the last_failure may not be present though]
  292. Which, in this case shows an error because the index did not exist:
  293. [source,console-result]
  294. --------------------------------------------------
  295. {
  296. "daily-snapshots" : {
  297. "version": 1,
  298. "modified_date": "2019-04-23T01:30:00.000Z",
  299. "modified_date_millis": 1556048137314,
  300. "policy" : {
  301. "schedule": "0 30 1 * * ?",
  302. "name": "<daily-snap-{now/d}>",
  303. "repository": "my_repository",
  304. "config": {
  305. "indices": ["data-*", "important"],
  306. "ignore_unavailable": false,
  307. "include_global_state": false
  308. },
  309. "retention": {
  310. "expire_after": "30d",
  311. "min_count": 5,
  312. "max_count": 50
  313. }
  314. },
  315. "stats": {
  316. "policy": "daily-snapshots",
  317. "snapshots_taken": 0,
  318. "snapshots_failed": 1,
  319. "snapshots_deleted": 0,
  320. "snapshot_deletion_failures": 0
  321. }
  322. "last_failure": { <1>
  323. "snapshot_name": "daily-snap-2019.04.02-lohisb5ith2n8hxacaq3mw",
  324. "time_string": "2019-04-02T01:30:00.000Z",
  325. "time": 1556042030000,
  326. "details": "{\"type\":\"index_not_found_exception\",\"reason\":\"no such index [important]\",\"resource.type\":\"index_or_alias\",\"resource.id\":\"important\",\"index_uuid\":\"_na_\",\"index\":\"important\",\"stack_trace\":\"[important] IndexNotFoundException[no such index [important]]\\n\\tat org.elasticsearch.cluster.metadata.IndexNameExpressionResolver$WildcardExpressionResolver.indexNotFoundException(IndexNameExpressionResolver.java:762)\\n\\tat org.elasticsearch.cluster.metadata.IndexNameExpressionResolver$WildcardExpressionResolver.innerResolve(IndexNameExpressionResolver.java:714)\\n\\tat org.elasticsearch.cluster.metadata.IndexNameExpressionResolver$WildcardExpressionResolver.resolve(IndexNameExpressionResolver.java:670)\\n\\tat org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.concreteIndices(IndexNameExpressionResolver.java:163)\\n\\tat org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.concreteIndexNames(IndexNameExpressionResolver.java:142)\\n\\tat org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.concreteIndexNames(IndexNameExpressionResolver.java:102)\\n\\tat org.elasticsearch.snapshots.SnapshotsService$1.execute(SnapshotsService.java:280)\\n\\tat org.elasticsearch.cluster.ClusterStateUpdateTask.execute(ClusterStateUpdateTask.java:47)\\n\\tat org.elasticsearch.cluster.service.MasterService.executeTasks(MasterService.java:687)\\n\\tat org.elasticsearch.cluster.service.MasterService.calculateTaskOutputs(MasterService.java:310)\\n\\tat org.elasticsearch.cluster.service.MasterService.runTasks(MasterService.java:210)\\n\\tat org.elasticsearch.cluster.service.MasterService$Batcher.run(MasterService.java:142)\\n\\tat org.elasticsearch.cluster.service.TaskBatcher.runIfNotProcessed(TaskBatcher.java:150)\\n\\tat org.elasticsearch.cluster.service.TaskBatcher$BatchedTask.run(TaskBatcher.java:188)\\n\\tat org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:688)\\n\\tat org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.runAndClean(PrioritizedEsThreadPoolExecutor.java:252)\\n\\tat org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:215)\\n\\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)\\n\\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)\\n\\tat java.base/java.lang.Thread.run(Thread.java:834)\\n\"}"
  327. } ,
  328. "next_execution": "2019-04-24T01:30:00.000Z",
  329. "next_execution_millis": 1556048160000
  330. }
  331. }
  332. --------------------------------------------------
  333. // TESTRESPONSE[skip:the presence of last_failure is asynchronous and will be present for users, but is untestable]
  334. <1> The last unsuccessfully initiated snapshot by this policy, along with the details of its failure
  335. In this case, it failed due to the "important" index not existing and
  336. `ignore_unavailable` setting being set to `false`.
  337. Updating the policy to change the `ignore_unavailable` setting is done using the
  338. same put snapshot lifecycle policy API:
  339. [source,console]
  340. --------------------------------------------------
  341. PUT /_slm/policy/daily-snapshots
  342. {
  343. "schedule": "0 30 1 * * ?",
  344. "name": "<daily-snap-{now/d}>",
  345. "repository": "my_repository",
  346. "config": {
  347. "indices": ["data-*", "important"],
  348. "ignore_unavailable": true,
  349. "include_global_state": false
  350. },
  351. "retention": {
  352. "expire_after": "30d",
  353. "min_count": 5,
  354. "max_count": 50
  355. }
  356. }
  357. --------------------------------------------------
  358. // TEST[continued]
  359. Another snapshot can immediately be executed to ensure the new policy works:
  360. [source,console]
  361. --------------------------------------------------
  362. POST /_slm/policy/daily-snapshots/_execute
  363. --------------------------------------------------
  364. // TEST[skip:we can't handle snapshots in docs tests]
  365. [source,console-result]
  366. --------------------------------------------------
  367. {
  368. "snapshot_name": "daily-snap-2019.04.24-tmtnyjtrsxkhbrrdcgg18a"
  369. }
  370. --------------------------------------------------
  371. // TESTRESPONSE[skip:we can't handle snapshots in docs tests]
  372. Now retrieving the policy shows that the policy has successfully been executed:
  373. [source,console]
  374. --------------------------------------------------
  375. GET /_slm/policy/daily-snapshots?human
  376. --------------------------------------------------
  377. // TEST[skip:we already tested this above and the output may not be available yet]
  378. Which now includes the successful snapshot information:
  379. [source,console-result]
  380. --------------------------------------------------
  381. {
  382. "daily-snapshots" : {
  383. "version": 2, <1>
  384. "modified_date": "2019-04-23T01:30:00.000Z",
  385. "modified_date_millis": 1556048137314,
  386. "policy" : {
  387. "schedule": "0 30 1 * * ?",
  388. "name": "<daily-snap-{now/d}>",
  389. "repository": "my_repository",
  390. "config": {
  391. "indices": ["data-*", "important"],
  392. "ignore_unavailable": true,
  393. "include_global_state": false
  394. },
  395. "retention": {
  396. "expire_after": "30d",
  397. "min_count": 5,
  398. "max_count": 50
  399. }
  400. },
  401. "stats": {
  402. "policy": "daily-snapshots",
  403. "snapshots_taken": 1,
  404. "snapshots_failed": 1,
  405. "snapshots_deleted": 0,
  406. "snapshot_deletion_failures": 0
  407. },
  408. "last_success": { <2>
  409. "snapshot_name": "daily-snap-2019.04.24-tmtnyjtrsxkhbrrdcgg18a",
  410. "time_string": "2019-04-24T16:43:49.316Z",
  411. "time": 1556124229316
  412. } ,
  413. "last_failure": {
  414. "snapshot_name": "daily-snap-2019.04.02-lohisb5ith2n8hxacaq3mw",
  415. "time_string": "2019-04-02T01:30:00.000Z",
  416. "time": 1556042030000,
  417. "details": "{\"type\":\"index_not_found_exception\",\"reason\":\"no such index [important]\",\"resource.type\":\"index_or_alias\",\"resource.id\":\"important\",\"index_uuid\":\"_na_\",\"index\":\"important\",\"stack_trace\":\"[important] IndexNotFoundException[no such index [important]]\\n\\tat org.elasticsearch.cluster.metadata.IndexNameExpressionResolver$WildcardExpressionResolver.indexNotFoundException(IndexNameExpressionResolver.java:762)\\n\\tat org.elasticsearch.cluster.metadata.IndexNameExpressionResolver$WildcardExpressionResolver.innerResolve(IndexNameExpressionResolver.java:714)\\n\\tat org.elasticsearch.cluster.metadata.IndexNameExpressionResolver$WildcardExpressionResolver.resolve(IndexNameExpressionResolver.java:670)\\n\\tat org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.concreteIndices(IndexNameExpressionResolver.java:163)\\n\\tat org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.concreteIndexNames(IndexNameExpressionResolver.java:142)\\n\\tat org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.concreteIndexNames(IndexNameExpressionResolver.java:102)\\n\\tat org.elasticsearch.snapshots.SnapshotsService$1.execute(SnapshotsService.java:280)\\n\\tat org.elasticsearch.cluster.ClusterStateUpdateTask.execute(ClusterStateUpdateTask.java:47)\\n\\tat org.elasticsearch.cluster.service.MasterService.executeTasks(MasterService.java:687)\\n\\tat org.elasticsearch.cluster.service.MasterService.calculateTaskOutputs(MasterService.java:310)\\n\\tat org.elasticsearch.cluster.service.MasterService.runTasks(MasterService.java:210)\\n\\tat org.elasticsearch.cluster.service.MasterService$Batcher.run(MasterService.java:142)\\n\\tat org.elasticsearch.cluster.service.TaskBatcher.runIfNotProcessed(TaskBatcher.java:150)\\n\\tat org.elasticsearch.cluster.service.TaskBatcher$BatchedTask.run(TaskBatcher.java:188)\\n\\tat org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:688)\\n\\tat org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.runAndClean(PrioritizedEsThreadPoolExecutor.java:252)\\n\\tat org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:215)\\n\\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)\\n\\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)\\n\\tat java.base/java.lang.Thread.run(Thread.java:834)\\n\"}"
  418. } ,
  419. "next_execution": "2019-04-24T01:30:00.000Z",
  420. "next_execution_millis": 1556048160000
  421. }
  422. }
  423. --------------------------------------------------
  424. // TESTRESPONSE[skip:the presence of last_failure and last_success is asynchronous and will be present for users, but is untestable]
  425. <1> The policy's version has been incremented because it was updated
  426. <2> The last successfully initiated snapshot information
  427. It is a good idea to test policies using the execute API to ensure they work.
  428. [[slm-get-stats]]
  429. === Get snapshot lifecycle stats API
  430. ++++
  431. <titleabbrev>Get snapshot lifecycle stats</titleabbrev>
  432. ++++
  433. Returns global and policy-level statistics about actions taken by {slm}.
  434. [[slm-api-stats-request]]
  435. ==== {api-request-title}
  436. `GET /_slm/stats`
  437. [[slm-api-stats-example]]
  438. ==== {api-examples-title}
  439. [source,console]
  440. --------------------------------------------------
  441. GET /_slm/stats
  442. --------------------------------------------------
  443. // TEST[continued]
  444. The API returns the following response:
  445. [source,js]
  446. --------------------------------------------------
  447. {
  448. "retention_runs": 13,
  449. "retention_failed": 0,
  450. "retention_timed_out": 0,
  451. "retention_deletion_time": "1.4s",
  452. "retention_deletion_time_millis": 1404,
  453. "policy_stats": [ ],
  454. "total_snapshots_taken": 1,
  455. "total_snapshots_failed": 1,
  456. "total_snapshots_deleted": 0,
  457. "total_snapshot_deletion_failures": 0
  458. }
  459. --------------------------------------------------
  460. // TESTRESPONSE[s/runs": 13/runs": $body.retention_runs/ s/_failed": 0/_failed": $body.retention_failed/ s/_timed_out": 0/_timed_out": $body.retention_timed_out/ s/"1.4s"/$body.retention_deletion_time/ s/1404/$body.retention_deletion_time_millis/ s/total_snapshots_taken": 1/total_snapshots_taken": $body.total_snapshots_taken/ s/total_snapshots_failed": 1/total_snapshots_failed": $body.total_snapshots_failed/ s/"policy_stats": [.*]/"policy_stats": $body.policy_stats/]
  461. [[slm-api-delete]]
  462. === Delete snapshot lifecycle policy API
  463. ++++
  464. <titleabbrev>Delete snapshot lifecycle policy</titleabbrev>
  465. ++++
  466. Deletes an existing snapshot lifecycle policy.
  467. [[slm-api-delete-request]]
  468. ==== {api-request-title}
  469. `DELETE /_slm/policy/<snapshot-lifecycle-policy-id>`
  470. [[slm-api-delete-desc]]
  471. ==== {api-description-title}
  472. A policy can be deleted by issuing a delete request with the policy id. Note
  473. that this prevents any future snapshots from being taken, but does not cancel
  474. any currently ongoing snapshots or remove any previously taken snapshots.
  475. [[slm-api-delete-path-params]]
  476. ==== {api-path-parms-title}
  477. `<snapshot-lifecycle-policy-id>`::
  478. (Required, string)
  479. ID of the snapshot lifecycle policy to delete.
  480. [[slm-api-delete-example]]
  481. ==== {api-examples-title}
  482. [source,console]
  483. --------------------------------------------------
  484. DELETE /_slm/policy/daily-snapshots
  485. --------------------------------------------------
  486. // TEST[continued]
  487. [[slm-api-execute-retention]]
  488. === Execute snapshot lifecycle retention API
  489. ++++
  490. <titleabbrev>Execute snapshot lifecycle retention</titleabbrev>
  491. ++++
  492. Deletes any expired snapshots based on lifecycle policy retention rules.
  493. [[slm-api-execute-retention-request]]
  494. ==== {api-request-title}
  495. `POST /_slm/_execute_retention`
  496. [[slm-api-execute-retention-desc]]
  497. ==== {api-description-title}
  498. While Snapshot Lifecycle Management retention is usually invoked through the global cluster settings
  499. for its schedule, it can sometimes be useful to invoke a retention run to expunge expired snapshots
  500. immediately. This API allows you to run a one-off retention run.
  501. [[slm-api-execute-retention-example]]
  502. ==== {api-examples-title}
  503. To immediately start snapshot retention, use the following request:
  504. [source,console]
  505. --------------------------------------------------
  506. POST /_slm/_execute_retention
  507. --------------------------------------------------
  508. This API returns the following response as retention runs asynchronously in the
  509. background:
  510. [source,console-result]
  511. --------------------------------------------------
  512. {
  513. "acknowledged": true
  514. }
  515. --------------------------------------------------
  516. [[slm-stop]]
  517. === Stop Snapshot Lifecycle Management API
  518. [subs="attributes"]
  519. ++++
  520. <titleabbrev>Stop Snapshot Lifecycle Management</titleabbrev>
  521. ++++
  522. Stop the Snapshot Lifecycle Management (SLM) plugin.
  523. [[slm-stop-request]]
  524. ==== {api-request-title}
  525. `POST /_slm/stop`
  526. [[slm-stop-desc]]
  527. ==== {api-description-title}
  528. Halts all snapshot lifecycle management operations and stops the SLM plugin.
  529. This is useful when you are performing maintenance on the cluster and need to
  530. prevent SLM from performing any actions on your indices. Note that this API does
  531. not stop any snapshots that are currently in progress, and that snapshots can
  532. still be taken manually via the <<slm-api-execute,Execute Policy API>> even
  533. when SLM is stopped.
  534. The API returns as soon as the stop request has been acknowledged, but the
  535. plugin might continue to run until in-progress operations complete and the plugin
  536. can be safely stopped. Use the <<slm-get-status, Get SLM Status>> API to see
  537. if SLM is running.
  538. ==== Request Parameters
  539. include::{docdir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
  540. ==== Authorization
  541. You must have the `manage_slm` cluster privilege to use this API.
  542. For more information, see <<security-privileges>>.
  543. [[slm-stop-example]]
  544. ==== {api-examples-title}
  545. Stops the SLM plugin.
  546. [source,console]
  547. --------------------------------------------------
  548. POST _slm/stop
  549. --------------------------------------------------
  550. // TEST[continued]
  551. If the request does not encounter errors, you receive the following result:
  552. [source,console-result]
  553. --------------------------------------------------
  554. {
  555. "acknowledged": true
  556. }
  557. --------------------------------------------------
  558. [[slm-start]]
  559. === Start Snapshot Lifecycle Management API
  560. [subs="attributes"]
  561. ++++
  562. <titleabbrev>Start Snapshot Lifecycle Management</titleabbrev>
  563. ++++
  564. Start the Snapshot Lifecycle Management (SLM) plugin.
  565. [[slm-start-request]]
  566. ==== {api-request-title}
  567. `POST /_slm/start`
  568. [[slm-start-desc]]
  569. ==== {api-description-title}
  570. Starts the SLM plugin if it is currently stopped. SLM is started
  571. automatically when the cluster is formed. Restarting SLM is only
  572. necessary if it has been stopped using the <<slm-stop, Stop SLM API>>.
  573. ==== Request Parameters
  574. include::{docdir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
  575. ==== Authorization
  576. You must have the `manage_slm` cluster privilege to use this API.
  577. For more information, see <<security-privileges>>.
  578. [[slm-start-example]]
  579. ==== {api-examples-title}
  580. Starts the SLM plugin.
  581. [source,console]
  582. --------------------------------------------------
  583. POST _slm/start
  584. --------------------------------------------------
  585. // TEST[continued]
  586. If the request succeeds, you receive the following result:
  587. [source,console-result]
  588. --------------------------------------------------
  589. {
  590. "acknowledged": true
  591. }
  592. --------------------------------------------------
  593. [[slm-get-status]]
  594. === Get Snapshot Lifecycle Management status API
  595. [subs="attributes"]
  596. ++++
  597. <titleabbrev>Get Snapshot Lifecycle Management status</titleabbrev>
  598. ++++
  599. Retrieves the current Snapshot Lifecycle Management (SLM) status.
  600. [[slm-get-status-request]]
  601. ==== {api-request-title}
  602. `GET /_slm/status`
  603. [[slm-get-status-desc]]
  604. ==== {api-description-title}
  605. Returns the status of the SLM plugin. The `operation_mode` field in the
  606. response shows one of three states: `STARTED`, `STOPPING`,
  607. or `STOPPED`. You can change the status of the SLM plugin with the
  608. <<slm-start, Start SLM>> and <<slm-stop, Stop SLM>> APIs.
  609. ==== Request Parameters
  610. include::{docdir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
  611. ==== Authorization
  612. You must have the `manage_slm` or `read_slm` or both cluster privileges to use this API.
  613. For more information, see <<security-privileges>>.
  614. [[slm-get-status-example]]
  615. ==== {api-examples-title}
  616. Gets the SLM plugin status.
  617. [source,console]
  618. --------------------------------------------------
  619. GET _slm/status
  620. --------------------------------------------------
  621. If the request succeeds, the body of the response shows the operation mode:
  622. [source,console-result]
  623. --------------------------------------------------
  624. {
  625. "operation_mode": "RUNNING"
  626. }
  627. --------------------------------------------------