restore-snapshot-api.asciidoc 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. // tag::restore-prereqs[]
  56. * If you use the {es} security features, you must have the `manage` or
  57. `cluster:admin/snapshot/*` cluster privilege to restore a snapshot.
  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. * If you restore a data stream, ensure the cluster contains a
  64. <<create-index-template,matching index template>> with data stream enabled.
  65. Without a matching index template, a data stream can't roll over or create
  66. backing indices.
  67. * If your snapshot contains data from App Search or Workplace Search, ensure
  68. you've restored the {enterprise-search-ref}/encryption-keys.html[Enterprise
  69. Search encryption key] before restoring the snapshot.
  70. // end::restore-prereqs[]
  71. [[restore-snapshot-api-path-params]]
  72. ==== {api-path-parms-title}
  73. `<repository>`::
  74. (Required, string)
  75. Name of the repository to restore a snapshot from.
  76. `<snapshot>`::
  77. (Required, string)
  78. Name of the snapshot to restore.
  79. [[restore-snapshot-api-query-params]]
  80. ==== {api-query-parms-title}
  81. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=master-timeout]
  82. `wait_for_completion`::
  83. (Optional, Boolean) If `true`, the request returns a response when the restore
  84. operation completes. The operation is complete when it finishes all attempts to
  85. <<monitor-restore,recover primary shards>> for restored indices.
  86. This applies even if one or more of the recovery attempts fail.
  87. +
  88. If `false`, the request returns a response when the restore
  89. operation initializes. Defaults to `false`.
  90. [role="child_attributes"]
  91. [[restore-snapshot-api-request-body]]
  92. ==== {api-request-body-title}
  93. `ignore_unavailable`::
  94. (Optional, Boolean) If `true`, the request ignores any index or data stream in
  95. `indices` that's missing from the snapshot. If `false`, the request returns an
  96. error for any missing index or data stream. Defaults to `false`.
  97. `ignore_index_settings`::
  98. (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`>>.
  99. +
  100. For data streams, this option only applies to restored backing indices. New
  101. backing indices are configured using the data stream's matching index template.
  102. `include_aliases`::
  103. (Optional, Boolean)
  104. If `true`, the request restores aliases for any restored data streams and
  105. indices. If `false`, the request doesn't restore aliases. Defaults to `true`.
  106. [[restore-snapshot-api-include-global-state]]
  107. `include_global_state`::
  108. +
  109. --
  110. (Optional, Boolean)
  111. If `true`, restore the cluster state. Defaults to `false`.
  112. The cluster state includes:
  113. // tag::cluster-state-contents[]
  114. * <<cluster-setting-types,Persistent cluster settings>>
  115. * <<index-templates,Index templates>>
  116. * <<indices-templates-v1,Legacy index templates>>
  117. * <<ingest,Ingest pipelines>>
  118. * <<index-lifecycle-management,{ilm-init} policies>>
  119. * For snapshots taken after 7.12.0, data stored in system indices, such as
  120. Watches and task records.
  121. // end::cluster-state-contents[]
  122. If `include_global_state` is `true` then the restore operation merges the
  123. legacy index templates in your cluster with the templates contained in the
  124. snapshot, replacing any existing ones whose name matches one in the snapshot.
  125. It completely removes all persistent settings, non-legacy index templates,
  126. ingest pipelines and {ilm-init} lifecycle policies that exist in your cluster
  127. and replaces them with the corresponding items from the snapshot.
  128. You can use the `feature_states` parameter to configure how system indices
  129. are restored from the cluster state.
  130. --
  131. [[restore-snapshot-api-feature-states]]
  132. `feature_states`::
  133. (Optional, array of strings)
  134. A comma-separated list of feature states you wish to restore. Each feature state contains one or more system indices. The list of feature states
  135. available in a given snapshot are returned by the <<get-snapshot-api-feature-states, Get Snapshot API>>. Note that feature
  136. states restored this way will completely replace any existing configuration, rather than returning an error if the system index already exists.
  137. Providing an empty array will restore no feature states, regardless of the value of `include_global_state`.
  138. +
  139. By default, all available feature states will be restored if `include_global_state` is `true`, and no feature states will be restored if
  140. `include_global_state` is `false`.
  141. [[restore-snapshot-api-index-settings]]
  142. `index_settings`::
  143. (Optional, object) Index settings to add or change in restored indices,
  144. including backing indices. You can't use this option to change
  145. <<index-number-of-shards,`index.number_of_shards`>>.
  146. +
  147. For data streams, this option only applies to restored backing indices. New
  148. backing indices are configured using the data stream's matching index template.
  149. `indices`::
  150. (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.
  151. [[restore-snapshot-api-partial]]
  152. `partial`::
  153. (Optional, Boolean)
  154. 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`.
  155. +
  156. If `true`, allows restoring a partial snapshot of indices with unavailable shards. Only shards that were successfully included in the snapshot
  157. will be restored. All missing shards will be recreated as empty.
  158. [[restore-snapshot-api-rename-pattern]]
  159. `rename_pattern`::
  160. (Optional, string)
  161. 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
  162. <<restore-snapshot-api-rename-replacement,`rename_replacement`>>.
  163. +
  164. The rename pattern is applied as defined by the regular expression that
  165. 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.
  166. [[restore-snapshot-api-rename-replacement]]
  167. `rename_replacement`::
  168. (Optional, string)
  169. Defines the rename replacement string. See <<restore-snapshot-api-rename-pattern,`rename_pattern`>> for more information.
  170. [[restore-snapshot-api-example]]
  171. ==== {api-examples-title}
  172. 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.
  173. For example, `index_1` will be renamed to `restored_index_1`. `index_2` will be renamed to `restored_index_2`.
  174. [source,console]
  175. ----
  176. POST /_snapshot/my_repository/snapshot_2/_restore?wait_for_completion=true
  177. {
  178. "indices": "index_1,index_2",
  179. "ignore_unavailable": true,
  180. "include_global_state": false,
  181. "rename_pattern": "index_(.+)",
  182. "rename_replacement": "restored_index_$1",
  183. "include_aliases": false
  184. }
  185. ----
  186. The API returns an acknowledgement if the request succeeds. If the request encounters errors, the response indicates any issues found, such as
  187. open indices that are blocking the restore operation from completing.