restore-snapshot-api.asciidoc 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 the {es} {security-features} are enabled, you must have the `manage`
  50. <<privileges-list-cluster,cluster privilege>> to use this API.
  51. [[restore-snapshot-api-desc]]
  52. ==== {api-description-title}
  53. Use the restore snapshot API to restore a snapshot of a cluster, including all data streams and indices in the snapshot. If you do not want to restore the entire snapshot, you can select specific data streams or indices to restore.
  54. You can run the restore operation on a cluster that contains an elected
  55. <<master-node,master node>> and has data nodes with enough capacity to accommodate the snapshot
  56. you are restoring. Existing indices can only be restored if they are
  57. <<indices-close,closed>> and have the same number of shards as the indices in
  58. the snapshot. The restore operation automatically opens restored indices if
  59. they were closed and creates new indices if they do not exist in the cluster.
  60. If a data stream is restored, its aliases and backing indices are also restored.
  61. Alternatively, you can restore individual backing indices without restoring an
  62. entire data stream. If you restore individual backing indices, they are not
  63. automatically added to any existing data stream. For example, if only the
  64. `.ds-logs-2099.03.08-00003` backing index is restored from a snapshot, it is not
  65. automatically added to the existing `logs` data stream.
  66. include::{es-ref-dir}/snapshot-restore/restore-snapshot.asciidoc[tag=index-settings-data-stream-warning]
  67. [[restore-snapshot-api-path-params]]
  68. ==== {api-path-parms-title}
  69. `<repository>`::
  70. (Required, string)
  71. Name of the repository to restore a snapshot from.
  72. `<snapshot>`::
  73. (Required, string)
  74. Name of the snapshot to restore.
  75. [[restore-snapshot-api-query-params]]
  76. ==== {api-query-parms-title}
  77. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=master-timeout]
  78. `wait_for_completion`::
  79. (Optional, Boolean) If `true`, the request returns a response when the restore
  80. operation completes. If `false`, the request returns a response when the restore
  81. operation initializes. Defaults to `false`.
  82. [role="child_attributes"]
  83. [[restore-snapshot-api-request-body]]
  84. ==== {api-request-body-title}
  85. `ignore_unavailable`::
  86. (Optional, Boolean)
  87. If `false`, the request returns an error for any data stream or index that is missing or closed. Defaults to `false`.
  88. +
  89. If `true`, the request ignores data streams and indices in `indices` that are missing or closed.
  90. `ignore_index_settings`::
  91. (Optional, string)
  92. A comma-separated list of index settings that should not be restored from a snapshot.
  93. `include_aliases`::
  94. (Optional, Boolean)
  95. If `true`, index aliases from the original snapshot are restored.
  96. Defaults to `true`.
  97. +
  98. If `false`, prevents index aliases from being restored together with associated
  99. indices.
  100. +
  101. This option doesn't affect data stream aliases. Restoring a data stream
  102. restores its aliases.
  103. [[restore-snapshot-api-include-global-state]]
  104. `include_global_state`::
  105. +
  106. --
  107. (Optional, Boolean)
  108. If `false`, the global state is not restored. Defaults to `false`.
  109. If `true`, the current global state is included in the restore operation.
  110. The global state includes:
  111. * Persistent cluster settings
  112. * Index templates
  113. * Legacy index templates
  114. * Ingest pipelines
  115. * {ilm-init} lifecycle policies
  116. * For snapshots taken after 7.12.0, data stored in system indices, such as Watches and task records, replacing any existing configuration (configurable via `feature_states`)
  117. If `include_global_state` is `true` then the restore operation merges the
  118. legacy index templates in your cluster with the templates contained in the
  119. snapshot, replacing any existing ones whose name matches one in the snapshot.
  120. It completely removes all persistent settings, non-legacy index templates,
  121. ingest pipelines and {ilm-init} lifecycle policies that exist in your cluster
  122. and replaces them with the corresponding items from the snapshot.
  123. --
  124. [[restore-snapshot-api-feature-states]]
  125. `feature_states`::
  126. (Optional, array of strings)
  127. 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
  128. available in a given snapshot are returned by the <<get-snapshot-api-feature-states, Get Snapshot API>>. Note that feature
  129. states restored this way will completely replace any existing configuration, rather than returning an error if the system index already exists.
  130. Providing an empty array will restore no feature states, regardless of the value of `include_global_state`.
  131. +
  132. By default, all available feature states will be restored if `include_global_state` is `true`, and no feature states will be restored if
  133. `include_global_state` is `false`.
  134. [[restore-snapshot-api-index-settings]]
  135. `index_settings`::
  136. (Optional, string)
  137. A comma-separated list of settings to add or change in all restored indices. Use this parameter to override index settings when restoring snapshots.
  138. +
  139. For data streams, these index settings are applied to the restored backing
  140. indices.
  141. +
  142. For more information regarding all the different index-level settings
  143. that you can specify, see
  144. <<index-modules,index modules>>.
  145. `indices`::
  146. (Optional, string)
  147. A comma-separated list of data streams and indices to restore from the snapshot.
  148. <<multi-index,Multi-index syntax>> is supported.
  149. +
  150. By default, a restore operation includes all data streams and indices in the snapshot. If this
  151. argument is provided, the restore operation only includes the specified data streams and indices.
  152. [[restore-snapshot-api-partial]]
  153. `partial`::
  154. (Optional, Boolean)
  155. 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`.
  156. +
  157. If `true`, allows restoring a partial snapshot of indices with unavailable shards. Only shards that were successfully included in the snapshot
  158. will be restored. All missing shards will be recreated as empty.
  159. [[restore-snapshot-api-rename-pattern]]
  160. `rename_pattern`::
  161. (Optional, string)
  162. 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
  163. <<restore-snapshot-api-rename-replacement,`rename_replacement`>>.
  164. +
  165. The rename pattern is applied as defined by the regular expression that
  166. 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.
  167. +
  168. The request will fail if two or more data streams or indices will be renamed into the same name.
  169. +
  170. include::{es-ref-dir}/snapshot-restore/restore-snapshot.asciidoc[tag=rename-restored-data-stream-tag]
  171. [[restore-snapshot-api-rename-replacement]]
  172. `rename_replacement`::
  173. (Optional, string)
  174. Defines the rename replacement string. See <<restore-snapshot-api-rename-pattern,`rename_pattern`>> for more information.
  175. [[restore-snapshot-api-example]]
  176. ==== {api-examples-title}
  177. 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.
  178. For example, `index_1` will be renamed to `restored_index_1`. `index_2` will be renamed to `restored_index_2`.
  179. [source,console]
  180. ----
  181. POST /_snapshot/my_repository/snapshot_2/_restore?wait_for_completion=true
  182. {
  183. "indices": "index_1,index_2",
  184. "ignore_unavailable": true,
  185. "include_global_state": false,
  186. "rename_pattern": "index_(.+)",
  187. "rename_replacement": "restored_index_$1",
  188. "include_aliases": false
  189. }
  190. ----
  191. The API returns an acknowledgement if the request succeeds. If the request encounters errors, the response indicates any issues found, such as
  192. open indices that are blocking the restore operation from completing.