create-snapshot-api.asciidoc 6.6 KB

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