restore-snapshot-api.asciidoc 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. [[restore-snapshot-api]]
  2. === Restore snapshot API
  3. ++++
  4. <titleabbrev>Restore 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. Restores a <<snapshot-restore,snapshot>> of a cluster or specified data streams and indices.
  12. ////
  13. [source,console]
  14. ----
  15. PUT /_snapshot/my_repository
  16. {
  17. "type": "fs",
  18. "settings": {
  19. "location": "my_backup_location"
  20. }
  21. }
  22. PUT /_snapshot/my_repository/my_snapshot?wait_for_completion=true
  23. PUT /index_1
  24. PUT /index_2
  25. PUT /index_3
  26. PUT /index_4
  27. PUT _snapshot/my_repository/snapshot_2?wait_for_completion=true
  28. {
  29. "indices": "index_1,index_2",
  30. "ignore_unavailable": true,
  31. "include_global_state": false,
  32. "metadata": {
  33. "taken_by": "Elastic Machine",
  34. "taken_because": "backup testing"
  35. }
  36. }
  37. POST /index_1/_close
  38. POST /index_2/_close
  39. POST /index_3/_close
  40. POST /index_4/_close
  41. ----
  42. // TESTSETUP
  43. ////
  44. [source,console]
  45. ----
  46. POST /_snapshot/my_repository/my_snapshot/_restore
  47. ----
  48. // TEST[s/_restore/_restore?wait_for_completion=true/]
  49. [[restore-snapshot-api-request]]
  50. ==== {api-request-title}
  51. `POST /_snapshot/<repository>/<snapshot>/_restore`
  52. [[restore-snapshot-api-prereqs]]
  53. ==== {api-prereq-title}
  54. * If you use {es} security features, you must have the `manage` or
  55. `cluster:admin/snapshot/*` cluster privilege to use this API.
  56. // tag::restore-prereqs[]
  57. * You can only restore a snapshot to a running cluster with an elected
  58. <<master-node,master node>>. The snapshot's repository must be
  59. <<snapshots-register-repository,registered>> and available to the cluster.
  60. * The snapshot and cluster versions must be compatible. See
  61. <<snapshot-restore-version-compatibility>>.
  62. * To restore a snapshot, the cluster's global metadata must be writable. Ensure
  63. there aren't any <<cluster-read-only,cluster blocks>> that prevent writes. The
  64. restore operation ignores <<index-modules-blocks,index blocks>>.
  65. * Before you restore a data stream, ensure the cluster contains a
  66. <<create-index-template,matching index template>> with data stream enabled. To
  67. check, use {kib}'s <<manage-index-templates,**Index Management**>> feature or
  68. the <<indices-get-template,get index template API>>:
  69. +
  70. [source,console]
  71. ----
  72. GET _index_template/*?filter_path=index_templates.name,index_templates.index_template.index_patterns,index_templates.index_template.data_stream
  73. ----
  74. +
  75. If no such template exists, you can <<create-index-template,create one>> or
  76. <<restore-entire-cluster,restore a cluster state>> that
  77. contains one. Without a matching index template, a data stream can't roll over
  78. or create backing indices.
  79. * If your snapshot contains data from App Search or Workplace Search, ensure
  80. you've restored the {enterprise-search-ref}/encryption-keys.html[Enterprise
  81. Search encryption key] before restoring the snapshot.
  82. // end::restore-prereqs[]
  83. [[restore-snapshot-api-path-params]]
  84. ==== {api-path-parms-title}
  85. `<repository>`::
  86. (Required, string)
  87. Name of the repository to restore a snapshot from.
  88. `<snapshot>`::
  89. (Required, string)
  90. Name of the snapshot to restore.
  91. [[restore-snapshot-api-query-params]]
  92. ==== {api-query-parms-title}
  93. include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=master-timeout]
  94. `wait_for_completion`::
  95. (Optional, Boolean) If `true`, the request returns a response when the restore
  96. operation completes. The operation is complete when it finishes all attempts to
  97. <<monitor-restore,recover primary shards>> for restored indices.
  98. This applies even if one or more of the recovery attempts fail.
  99. +
  100. If `false`, the request returns a response when the restore
  101. operation initializes. Defaults to `false`.
  102. [role="child_attributes"]
  103. [[restore-snapshot-api-request-body]]
  104. ==== {api-request-body-title}
  105. `ignore_unavailable`::
  106. (Optional, Boolean) If `true`, the request ignores any index or data stream in
  107. `indices` that's missing from the snapshot. If `false`, the request returns an
  108. error for any missing index or data stream. Defaults to `false`.
  109. `ignore_index_settings`::
  110. (Optional, string or array of strings) Index settings to not restore from the snapshot. You can't use this option to ignore <<index-number-of-shards,`index.number_of_shards`>>.
  111. +
  112. For data streams, this option only applies to restored backing indices. New
  113. backing indices are configured using the data stream's matching index template.
  114. `include_aliases`::
  115. (Optional, Boolean)
  116. If `true`, the request restores aliases for any restored data streams and
  117. indices. If `false`, the request doesn't restore aliases. Defaults to `true`.
  118. [[restore-snapshot-api-include-global-state]]
  119. `include_global_state`::
  120. +
  121. --
  122. (Optional, Boolean)
  123. If `true`, restore the cluster state. Defaults to `false`.
  124. The cluster state includes:
  125. // tag::cluster-state-contents[]
  126. * <<cluster-setting-types,Persistent cluster settings>>
  127. * <<index-templates,Index templates>>
  128. * <<indices-templates-v1,Legacy index templates>>
  129. * <<ingest,Ingest pipelines>>
  130. * <<index-lifecycle-management,{ilm-init} policies>>
  131. * <<script-stored-scripts,Stored scripts>>
  132. * For snapshots taken after 7.12.0, <<feature-state,feature states>>
  133. // end::cluster-state-contents[]
  134. If `include_global_state` is `true` then the restore operation merges the
  135. legacy index templates in your cluster with the templates contained in the
  136. snapshot, replacing any existing ones whose name matches one in the snapshot.
  137. It completely removes all persistent settings, non-legacy index templates,
  138. ingest pipelines and {ilm-init} lifecycle policies that exist in your cluster
  139. and replaces them with the corresponding items from the snapshot.
  140. Use the `feature_states` parameter to configure how feature states are restored.
  141. If `include_global_state` is `true` and a snapshot was created without a global
  142. state then the restore request will fail.
  143. --
  144. [[restore-snapshot-api-feature-states]]
  145. `feature_states`::
  146. (Optional, array of strings)
  147. <<feature-state,Feature states>> to restore.
  148. +
  149. If `include_global_state` is `true`, the request restores all feature states
  150. in the snapshot by default. If `include_global_state` is `false`, the request
  151. restores no feature states by default. Note that specifying an empty array
  152. will result in the default behavior. To restore no feature states, regardless
  153. of the `include_global_state` value, specify an array containing only the value
  154. `none` (`["none"]`).
  155. [[restore-snapshot-api-index-settings]]
  156. `index_settings`::
  157. (Optional, object) Index settings to add or change in restored indices,
  158. including backing indices. You can't use this option to change
  159. <<index-number-of-shards,`index.number_of_shards`>>.
  160. +
  161. For data streams, this option only applies to restored backing indices. New
  162. backing indices are configured using the data stream's matching index template.
  163. `indices`::
  164. (Optional, string or array of strings) Comma-separated list of indices and data
  165. streams to restore. Supports <<api-multi-index,multi-target syntax>>. Defaults
  166. to all regular indices and regular data streams in the snapshot.
  167. +
  168. You can't use this parameter to restore <<system-indices,system indices or
  169. system data streams>>. Use
  170. <<restore-snapshot-api-feature-states,`feature_states`>> instead.
  171. [[restore-snapshot-api-partial]]
  172. `partial`::
  173. (Optional, Boolean)
  174. If `false`, the entire restore operation will fail if one or more indices included in the snapshot do not have all primary shards available. Defaults to `false`.
  175. +
  176. If `true`, allows restoring a partial snapshot of indices with unavailable shards. Only shards that were successfully included in the snapshot
  177. will be restored. All missing shards will be recreated as empty.
  178. [[restore-snapshot-api-rename-pattern]]
  179. `rename_pattern`::
  180. (Optional, string)
  181. Defines a rename pattern to apply to restored data streams and indices. Data streams and indices matching the rename pattern will be renamed according to
  182. <<restore-snapshot-api-rename-replacement,`rename_replacement`>>.
  183. +
  184. The rename pattern is applied as defined by the regular expression that
  185. supports referencing the original text, according to the https://docs.oracle.com/javase/8/docs/api/java/util/regex/Matcher.html#appendReplacement-java.lang.StringBuffer-java.lang.String-[`appendReplacement`] logic.
  186. [[restore-snapshot-api-rename-replacement]]
  187. `rename_replacement`::
  188. (Optional, string)
  189. Defines the rename replacement string. See <<restore-snapshot-api-rename-pattern,`rename_pattern`>> for more information.
  190. [[restore-snapshot-api-example]]
  191. ==== {api-examples-title}
  192. [[restore-snapshot-api-example-rename]]
  193. ===== Restore renamed
  194. The following request restores `index_1` and `index_2` from `snapshot_2`. The `rename_pattern` and `rename_replacement` parameters indicate any index matching the regular expression `index_(.+)` will be renamed using the pattern `restored_index_$1` when restored.
  195. For example, `index_1` will be renamed to `restored_index_1`. `index_2` will be renamed to `restored_index_2`.
  196. [source,console]
  197. ----
  198. POST /_snapshot/my_repository/snapshot_2/_restore?wait_for_completion=true
  199. {
  200. "indices": "index_1,index_2",
  201. "ignore_unavailable": true,
  202. "include_global_state": false,
  203. "rename_pattern": "index_(.+)",
  204. "rename_replacement": "restored_index_$1",
  205. "include_aliases": false
  206. }
  207. ----
  208. The API returns an acknowledgement if the request succeeds. If the request encounters errors, the response indicates any issues found, such as
  209. open indices that are blocking the restore operation from completing.
  210. [[restore-snapshot-api-example-inplace]]
  211. ===== Restore in-place
  212. You may want to restore an index in-place, for example when no alternative
  213. options surface after the <<cluster-allocation-explain>> API reports
  214. `no_valid_shard_copy`.
  215. The following request <<indices-close,closes>> `index_1` and then restores it
  216. in-place from the `snapshot_2` snapshot in the `my_repository` repository.
  217. [source,console]
  218. ----
  219. POST index_1/_close
  220. POST /_snapshot/my_repository/snapshot_2/_restore?wait_for_completion=true
  221. {
  222. "indices": "index_1"
  223. }
  224. ----