create-snapshot-api.asciidoc 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. [[create-snapshot-api]]
  2. === Create snapshot API
  3. ++++
  4. <titleabbrev>Create snapshot</titleabbrev>
  5. ++++
  6. <<snapshots-take-snapshot,Takes a snapshot>> of a cluster or specified data
  7. streams and indices.
  8. ////
  9. [source,console]
  10. -----------------------------------
  11. PUT /_snapshot/my_repository
  12. {
  13. "type": "fs",
  14. "settings": {
  15. "location": "my_backup_location"
  16. }
  17. }
  18. -----------------------------------
  19. // TESTSETUP
  20. ////
  21. [source,console]
  22. -----------------------------------
  23. PUT /_snapshot/my_repository/my_snapshot
  24. -----------------------------------
  25. // TEST[s/my_snapshot/my_snapshot?wait_for_completion=true/]
  26. [[create-snapshot-api-request]]
  27. ==== {api-request-title}
  28. `PUT /_snapshot/<repository>/<snapshot>`
  29. `POST /_snapshot/<repository>/<snapshot>`
  30. [[create-snapshot-api-prereqs]]
  31. ==== {api-prereq-title}
  32. * If the {es} {security-features} are enabled, you must have the
  33. `create_snapshot` or `manage` <<privileges-list-cluster,cluster privilege>> to
  34. use this API.
  35. [[create-snapshot-api-path-params]]
  36. ==== {api-path-parms-title}
  37. `<repository>`::
  38. (Required, string)
  39. Name of the snapshot repository.
  40. `<snapshot>`::
  41. (Required, string)
  42. Name of the snapshot. Supports <<api-date-math-index-names,date math>>. Must be
  43. unique within the snapshot repository.
  44. [[create-snapshot-api-query-params]]
  45. ==== {api-query-parms-title}
  46. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=master-timeout]
  47. `wait_for_completion`::
  48. (Optional, Boolean) If `true`, the request returns a response when the snapshot
  49. is complete. If `false`, the request returns a response when the snapshot
  50. initializes. Defaults to `false`.
  51. [role="child_attributes"]
  52. [[create-snapshot-api-request-body]]
  53. ==== {api-request-body-title}
  54. // Set an attribute so we can reuse these params with anchors
  55. :page-id: create-snapshot-api
  56. // tag::snapshot-config[]
  57. `expand_wildcards`::
  58. +
  59. --
  60. (Optional, string) Determines how wildcard patterns in the `indices` parameter
  61. match data streams and indices. Supports comma-separated values, such as
  62. `open,hidden`. Defaults to `all`. Valid values are:
  63. `all`:::
  64. Match any data stream or index, including <<hidden,hidden>> ones.
  65. `open`:::
  66. Match open indices and data streams.
  67. `closed`:::
  68. Match closed indices and data streams.
  69. `hidden`:::
  70. Match hidden data streams and indices. Must be combined with `open`, `closed`,
  71. or both.
  72. `none`:::
  73. Don't expand wildcard patterns.
  74. --
  75. `ignore_unavailable`::
  76. (Optional, Boolean)
  77. If `false`, the snapshot fails if any data stream or index in `indices` is
  78. missing or closed. If `true`, the snapshot ignores missing or closed data
  79. streams and indices. Defaults to `false`.
  80. `include_global_state`::
  81. +
  82. --
  83. (Optional, Boolean)
  84. If `true`, include the cluster state in the snapshot. Defaults to `true`.
  85. The cluster state includes:
  86. include::restore-snapshot-api.asciidoc[tag=cluster-state-contents]
  87. --
  88. `indices`::
  89. (Optional, string or array of strings)
  90. Comma-separated list of data streams and indices to include in the snapshot.
  91. Supports <<api-multi-index,multi-index syntax>>. Defaults to an empty array
  92. (`[]`), which includes all data streams and indices, including system indices.
  93. +
  94. To exclude all data streams and indices, use `-*` or `none`.
  95. [id="{page-id}-feature-states"]
  96. `feature_states`::
  97. (Optional, array of strings)
  98. <<feature-state,Feature states>> to include in the snapshot. To get a list of
  99. possible values and their descriptions, use the <<get-features-api,get features
  100. API>>.
  101. +
  102. If `include_global_state` is `true`, the snapshot includes all feature states by
  103. default. If `include_global_state` is `false`, the snapshot includes no feature
  104. states by default.
  105. +
  106. To exclude all feature states, regardless of the `include_global_state` value,
  107. specify an empty array (`[]`) or `none`.
  108. `metadata`::
  109. (Optional, object)
  110. Attaches arbitrary metadata to the snapshot, such as a record of who took the snapshot, why it was taken, or any other useful data. Metadata must be less than 1024 bytes.
  111. [id="{page-id}-partial"]
  112. `partial`::
  113. (Optional, Boolean)
  114. If `false`, the entire snapshot will fail if one or more indices included in the snapshot do not have all primary shards available. Defaults to `false`.
  115. +
  116. If `true`, allows taking a partial snapshot of indices with unavailable shards.
  117. // end::snapshot-config[]
  118. // Unset the attribute
  119. :!page-id:
  120. [[create-snapshot-api-example]]
  121. ==== {api-examples-title}
  122. The following request takes a snapshot of `index_1` and `index_2`.
  123. [source,console]
  124. -----------------------------------
  125. PUT /_snapshot/my_repository/snapshot_2?wait_for_completion=true
  126. {
  127. "indices": "index_1,index_2",
  128. "ignore_unavailable": true,
  129. "include_global_state": false,
  130. "metadata": {
  131. "taken_by": "user123",
  132. "taken_because": "backup before upgrading"
  133. }
  134. }
  135. -----------------------------------
  136. The API returns the following response:
  137. [source,console-result]
  138. ----
  139. {
  140. "snapshot": {
  141. "snapshot": "snapshot_2",
  142. "uuid": "vdRctLCxSketdKb54xw67g",
  143. "repository": "my_repository",
  144. "version_id": <version_id>,
  145. "version": <version>,
  146. "indices": [],
  147. "data_streams": [],
  148. "feature_states": [],
  149. "include_global_state": false,
  150. "metadata": {
  151. "taken_by": "user123",
  152. "taken_because": "backup before upgrading"
  153. },
  154. "state": "SUCCESS",
  155. "start_time": "2020-06-25T14:00:28.850Z",
  156. "start_time_in_millis": 1593093628850,
  157. "end_time": "2020-06-25T14:00:28.850Z",
  158. "end_time_in_millis": 1593094752018,
  159. "duration_in_millis": 0,
  160. "failures": [],
  161. "shards": {
  162. "total": 0,
  163. "failed": 0,
  164. "successful": 0
  165. }
  166. }
  167. }
  168. ----
  169. // TESTRESPONSE[s/"uuid": "vdRctLCxSketdKb54xw67g"/"uuid": $body.snapshot.uuid/]
  170. // TESTRESPONSE[s/"version_id": <version_id>/"version_id": $body.snapshot.version_id/]
  171. // TESTRESPONSE[s/"version": <version>/"version": $body.snapshot.version/]
  172. // TESTRESPONSE[s/"start_time": "2020-06-25T14:00:28.850Z"/"start_time": $body.snapshot.start_time/]
  173. // TESTRESPONSE[s/"start_time_in_millis": 1593093628850/"start_time_in_millis": $body.snapshot.start_time_in_millis/]
  174. // TESTRESPONSE[s/"end_time": "2020-06-25T14:00:28.850Z"/"end_time": $body.snapshot.end_time/]
  175. // TESTRESPONSE[s/"end_time_in_millis": 1593094752018/"end_time_in_millis": $body.snapshot.end_time_in_millis/]
  176. // TESTRESPONSE[s/"duration_in_millis": 0/"duration_in_millis": $body.snapshot.duration_in_millis/]