restore-snapshot-api.asciidoc 9.0 KB

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