restore-snapshot-api.asciidoc 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. "indices": "*,-.*",
  44. "feature_states": [ "geoip" ]
  45. }
  46. ----
  47. // TEST[s/_restore/_restore?wait_for_completion=true/]
  48. // TEST[s/",/"/]
  49. // TEST[s/"feature_states": \[ "geoip" \]//]
  50. [[restore-snapshot-api-request]]
  51. ==== {api-request-title}
  52. `POST /_snapshot/<repository>/<snapshot>/_restore`
  53. [[restore-snapshot-api-prereqs]]
  54. ==== {api-prereq-title}
  55. * If you use {es} security features, you must have the `manage` or
  56. `cluster:admin/snapshot/*` cluster privilege to use this API.
  57. // tag::restore-prereqs[]
  58. * You can only restore a snapshot to a running cluster with an elected
  59. <<master-node,master node>>. The snapshot's repository must be
  60. <<snapshots-register-repository,registered>> and available to the cluster.
  61. * The snapshot and cluster versions must be compatible. See
  62. <<snapshot-restore-version-compatibility>>.
  63. * To restore a snapshot, the cluster's global metadata must be writable. Ensure
  64. there aren't any <<cluster-read-only,cluster blocks>> that prevent writes. The
  65. restore operation ignores <<index-modules-blocks,index blocks>>.
  66. * Before you restore a data stream, ensure the cluster contains a
  67. <<create-index-template,matching index template>> with data stream enabled. To
  68. check, use {kib}'s <<manage-index-templates,**Index Management**>> feature or
  69. the <<indices-get-template,get index template API>>:
  70. +
  71. [source,console]
  72. ----
  73. GET /_index_template/*?filter_path=index_templates.name,index_templates.index_template.index_patterns,index_templates.index_template.data_stream
  74. ----
  75. +
  76. If no such template exists, you can <<create-index-template,create one>> or
  77. <<restore-entire-cluster,restore a cluster state>> that
  78. contains one. Without a matching index template, a data stream can't roll over
  79. or create backing indices.
  80. * If your snapshot contains data from App Search or Workplace Search, ensure
  81. you've restored the {enterprise-search-ref}/encryption-keys.html[Enterprise
  82. Search encryption key] before restoring the snapshot.
  83. // end::restore-prereqs[]
  84. [[restore-snapshot-api-path-params]]
  85. ==== {api-path-parms-title}
  86. `<repository>`::
  87. (Required, string)
  88. Name of the repository to restore a snapshot from.
  89. `<snapshot>`::
  90. (Required, string)
  91. Name of the snapshot to restore.
  92. [[restore-snapshot-api-query-params]]
  93. ==== {api-query-parms-title}
  94. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=master-timeout]
  95. `wait_for_completion`::
  96. (Optional, Boolean) If `true`, the request returns a response when the restore
  97. operation completes. The operation is complete when it finishes all attempts to
  98. <<monitor-restore,recover primary shards>> for restored indices.
  99. This applies even if one or more of the recovery attempts fail.
  100. +
  101. If `false`, the request returns a response when the restore
  102. operation initializes. Defaults to `false`.
  103. [role="child_attributes"]
  104. [[restore-snapshot-api-request-body]]
  105. ==== {api-request-body-title}
  106. `ignore_unavailable`::
  107. (Optional, Boolean) If `true`, the request ignores any index or data stream in
  108. `indices` that's missing from the snapshot. If `false`, the request returns an
  109. error for any missing index or data stream. Defaults to `false`.
  110. `ignore_index_settings`::
  111. (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`>>.
  112. +
  113. For data streams, this option only applies to restored backing indices. New
  114. backing indices are configured using the data stream's matching index template.
  115. `include_aliases`::
  116. (Optional, Boolean)
  117. If `true`, the request restores aliases for any restored data streams and
  118. indices. If `false`, the request doesn't restore aliases. Defaults to `true`.
  119. [[restore-snapshot-api-include-global-state]]
  120. `include_global_state`::
  121. +
  122. --
  123. (Optional, Boolean)
  124. If `true`, restore the cluster state. Defaults to `false`.
  125. The cluster state includes:
  126. // tag::cluster-state-contents[]
  127. * <<cluster-setting-types,Persistent cluster settings>>
  128. * <<index-templates,Index templates>>
  129. * <<indices-templates-v1,Legacy index templates>>
  130. * <<ingest,Ingest pipelines>>
  131. * <<index-lifecycle-management,{ilm-init} policies>>
  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. --
  142. [[restore-snapshot-api-feature-states]]
  143. `feature_states`::
  144. (Optional, array of strings)
  145. <<feature-state,Feature states>> to restore.
  146. +
  147. If `include_global_state` is `true`, the request restores all feature states
  148. in the snapshot by default. If `include_global_state` is `false`, the request
  149. restores no feature states by default. To restore no feature states, regardless
  150. of the `include_global_state` value, specify an empty array (`[]`).
  151. [[restore-snapshot-api-index-settings]]
  152. `index_settings`::
  153. (Optional, object) Index settings to add or change in restored indices,
  154. including backing indices. You can't use this option to change
  155. <<index-number-of-shards,`index.number_of_shards`>>.
  156. +
  157. For data streams, this option only applies to restored backing indices. New
  158. backing indices are configured using the data stream's matching index template.
  159. `indices`::
  160. (Optional, string or array of strings) Comma-separated list of indices and data streams to restore. Supports <<api-multi-index,multi-target syntax>>. Defaults to all indices and data streams in the snapshot, including system indices.
  161. [[restore-snapshot-api-partial]]
  162. `partial`::
  163. (Optional, Boolean)
  164. 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`.
  165. +
  166. If `true`, allows restoring a partial snapshot of indices with unavailable shards. Only shards that were successfully included in the snapshot
  167. will be restored. All missing shards will be recreated as empty.
  168. [[restore-snapshot-api-rename-pattern]]
  169. `rename_pattern`::
  170. (Optional, string)
  171. 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
  172. <<restore-snapshot-api-rename-replacement,`rename_replacement`>>.
  173. +
  174. The rename pattern is applied as defined by the regular expression that
  175. 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.
  176. [[restore-snapshot-api-rename-replacement]]
  177. `rename_replacement`::
  178. (Optional, string)
  179. Defines the rename replacement string. See <<restore-snapshot-api-rename-pattern,`rename_pattern`>> for more information.
  180. [[restore-snapshot-api-example]]
  181. ==== {api-examples-title}
  182. 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.
  183. For example, `index_1` will be renamed to `restored_index_1`. `index_2` will be renamed to `restored_index_2`.
  184. [source,console]
  185. ----
  186. POST /_snapshot/my_repository/snapshot_2/_restore?wait_for_completion=true
  187. {
  188. "indices": "index_1,index_2",
  189. "ignore_unavailable": true,
  190. "include_global_state": false,
  191. "rename_pattern": "index_(.+)",
  192. "rename_replacement": "restored_index_$1",
  193. "include_aliases": false
  194. }
  195. ----
  196. The API returns an acknowledgement if the request succeeds. If the request encounters errors, the response indicates any issues found, such as
  197. open indices that are blocking the restore operation from completing.