create-snapshot-api.asciidoc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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-target syntax>>. Defaults to an empty array
  92. (`[]`), which includes all regular data streams and regular indices. To exclude
  93. all data streams and indices, use `-*`.
  94. +
  95. You can't use this parameter to include or exclude <<system-indices,system
  96. indices or system data streams>> from a snapshot. Use
  97. <<{page-id}-feature-states,`feature_states`>> instead.
  98. [id="{page-id}-feature-states"]
  99. `feature_states`::
  100. (Optional, array of strings)
  101. <<feature-state,Feature states>> to include in the snapshot. To get a list of
  102. possible values and their descriptions, use the <<get-features-api,get features
  103. API>>.
  104. +
  105. If `include_global_state` is `true`, the snapshot includes all feature states by
  106. default. If `include_global_state` is `false`, the snapshot includes no feature
  107. states by default.
  108. +
  109. To exclude all feature states, regardless of the `include_global_state` value,
  110. specify an empty array (`[]`) or `none`.
  111. `metadata`::
  112. (Optional, object)
  113. 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.
  114. [id="{page-id}-partial"]
  115. `partial`::
  116. (Optional, Boolean)
  117. 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`.
  118. +
  119. If `true`, allows taking a partial snapshot of indices with unavailable shards.
  120. // end::snapshot-config[]
  121. // Unset the attribute
  122. :!page-id:
  123. [[create-snapshot-api-example]]
  124. ==== {api-examples-title}
  125. The following request takes a snapshot of `index_1` and `index_2`.
  126. [source,console]
  127. -----------------------------------
  128. PUT /_snapshot/my_repository/snapshot_2?wait_for_completion=true
  129. {
  130. "indices": "index_1,index_2",
  131. "ignore_unavailable": true,
  132. "include_global_state": false,
  133. "metadata": {
  134. "taken_by": "user123",
  135. "taken_because": "backup before upgrading"
  136. }
  137. }
  138. -----------------------------------
  139. The API returns the following response:
  140. [source,console-result]
  141. ----
  142. {
  143. "snapshot": {
  144. "snapshot": "snapshot_2",
  145. "uuid": "vdRctLCxSketdKb54xw67g",
  146. "repository": "my_repository",
  147. "version_id": <version_id>,
  148. "version": <version>,
  149. "indices": [],
  150. "data_streams": [],
  151. "feature_states": [],
  152. "include_global_state": false,
  153. "metadata": {
  154. "taken_by": "user123",
  155. "taken_because": "backup before upgrading"
  156. },
  157. "state": "SUCCESS",
  158. "start_time": "2020-06-25T14:00:28.850Z",
  159. "start_time_in_millis": 1593093628850,
  160. "end_time": "2020-06-25T14:00:28.850Z",
  161. "end_time_in_millis": 1593094752018,
  162. "duration_in_millis": 0,
  163. "failures": [],
  164. "shards": {
  165. "total": 0,
  166. "failed": 0,
  167. "successful": 0
  168. }
  169. }
  170. }
  171. ----
  172. // TESTRESPONSE[s/"uuid": "vdRctLCxSketdKb54xw67g"/"uuid": $body.snapshot.uuid/]
  173. // TESTRESPONSE[s/"version_id": <version_id>/"version_id": $body.snapshot.version_id/]
  174. // TESTRESPONSE[s/"version": <version>/"version": $body.snapshot.version/]
  175. // TESTRESPONSE[s/"start_time": "2020-06-25T14:00:28.850Z"/"start_time": $body.snapshot.start_time/]
  176. // TESTRESPONSE[s/"start_time_in_millis": 1593093628850/"start_time_in_millis": $body.snapshot.start_time_in_millis/]
  177. // TESTRESPONSE[s/"end_time": "2020-06-25T14:00:28.850Z"/"end_time": $body.snapshot.end_time/]
  178. // TESTRESPONSE[s/"end_time_in_millis": 1593094752018/"end_time_in_millis": $body.snapshot.end_time_in_millis/]
  179. // TESTRESPONSE[s/"duration_in_millis": 0/"duration_in_millis": $body.snapshot.duration_in_millis/]