restore-snapshot.asciidoc 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. [[snapshots-restore-snapshot]]
  2. == Restore a snapshot
  3. ////
  4. [source,console]
  5. -----------------------------------
  6. PUT /_snapshot/my_backup
  7. {
  8. "type": "fs",
  9. "settings": {
  10. "location": "my_backup_location"
  11. }
  12. }
  13. PUT /_snapshot/my_backup/snapshot_1?wait_for_completion=true
  14. -----------------------------------
  15. // TESTSETUP
  16. ////
  17. Use the <<restore-snapshot-api,restore snapshot API>> to restore
  18. a snapshot of a cluster or specified data streams and indices:
  19. [source,console]
  20. -----------------------------------
  21. POST /_snapshot/my_backup/snapshot_1/_restore
  22. -----------------------------------
  23. // TEST[s/_restore/_restore?wait_for_completion=true/]
  24. By default, all data streams and indices in the snapshot are restored, but the cluster state is
  25. *not* restored. Use the `indices` parameter to restore only specific data streams or indices. This parameter
  26. supports <<multi-index,multi-target syntax>>. To include the global cluster state, set
  27. `include_global_state` to `true` in the restore request body.
  28. Because all indices in the snapshot are restored by default, all system indices will be restored
  29. by default as well.
  30. [WARNING]
  31. ====
  32. Each data stream requires a matching
  33. <<create-index-template,index template>>. The stream uses this
  34. template to create new backing indices.
  35. When restoring a data stream, ensure a matching template exists for the stream.
  36. You can do this using one of the following methods:
  37. * Check for existing templates that match the stream. If no matching template
  38. exists, <<create-index-template,create one>>.
  39. * Restore a global cluster state that includes a matching template for the
  40. stream.
  41. If no index template matches a data stream, the stream cannot
  42. <<manually-roll-over-a-data-stream,roll over>> or create new backing indices.
  43. ====
  44. The `rename_pattern`
  45. and `rename_replacement` options can be also used to rename data streams and indices on restore
  46. using regular expression that 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.
  47. [[rename-restored-data-stream]]
  48. // tag::rename-restored-data-stream-tag[]
  49. If you rename a restored data stream, its backing indices are also
  50. renamed. For example, if you rename the `logs` data stream to `restored-logs`,
  51. the backing index `.ds-logs-2099.03.09-000005` is renamed to
  52. `.ds-restored-logs-2099.03.09-000005`.
  53. [WARNING]
  54. ====
  55. If you rename a restored stream, ensure an index template matches the new stream
  56. name. If no index template matches the stream, it cannot
  57. <<manually-roll-over-a-data-stream,roll over>> or create new backing indices.
  58. ====
  59. // end::rename-restored-data-stream-tag[]
  60. To prevent index aliases from being restored together with associated indices,
  61. set `include_aliases` to `false`. This option doesn't affect data stream
  62. aliases. Restoring a data stream restores its aliases.
  63. [source,console]
  64. -----------------------------------
  65. POST /_snapshot/my_backup/snapshot_1/_restore
  66. {
  67. "indices": "data_stream_1,index_1,index_2",
  68. "ignore_unavailable": true,
  69. "include_global_state": false, <1>
  70. "rename_pattern": "index_(.+)",
  71. "rename_replacement": "restored_index_$1",
  72. "include_aliases": false
  73. }
  74. -----------------------------------
  75. // TEST[continued]
  76. <1> By default, `include_global_state` is `false`, meaning the snapshot's
  77. cluster state and feature states are not restored.
  78. +
  79. If `true` then the restore operation merges the legacy index templates in your
  80. cluster with the templates contained in the snapshot, replacing any existing
  81. ones whose name matches one in the snapshot. It completely removes all
  82. persistent settings, non-legacy index templates, ingest pipelines and
  83. {ilm-init} lifecycle policies that exist in your cluster and replaces them with
  84. the corresponding items from the snapshot.
  85. The restore operation must be performed on a functioning cluster. However, an
  86. existing index can be only restored if it's <<indices-close,closed>> and
  87. has the same number of shards as the index in the snapshot. The restore
  88. operation automatically opens restored indices if they were closed and creates
  89. new indices if they didn't exist in the cluster.
  90. If a data stream is restored, its backing indices are also restored. The restore
  91. operation automatically opens restored backing indices if they were closed.
  92. In addition to entire data streams, you can restore only specific backing
  93. indices from a snapshot. However, restored backing indices are not automatically
  94. added to any existing data streams. For example, if only the
  95. `.ds-logs-2099.03.08-000003` backing index is restored from a snapshot, it is
  96. not automatically added to the existing `logs` data stream.
  97. [discrete]
  98. === Partial restore
  99. By default, the entire restore operation will fail if one or more indices or backing indices participating in the operation don't have
  100. snapshots of all shards available. It can occur if some shards failed to snapshot for example. It is still possible to
  101. restore such indices by setting `partial` to `true`. Please note, that only successfully snapshotted shards will be
  102. restored in this case and all missing shards will be recreated empty.
  103. [discrete]
  104. [[change-index-settings-during-restore]]
  105. === Changing index settings during restore
  106. Use the <<restore-snapshot-api-index-settings,`index_settings`>> parameter
  107. to override index settings during the restore process. For example, the
  108. following request will restore the index `index_1` without creating any
  109. replicas while switching back to the default refresh interval:
  110. [source,console]
  111. -----------------------------------
  112. POST /_snapshot/my_backup/snapshot_1/_restore
  113. {
  114. "indices": "index_1",
  115. "ignore_unavailable": true,
  116. "index_settings": {
  117. "index.number_of_replicas": 0
  118. },
  119. "ignore_index_settings": [
  120. "index.refresh_interval"
  121. ]
  122. }
  123. -----------------------------------
  124. // TEST[continued]
  125. NOTE: Some settings such as `index.number_of_shards` cannot be changed during the restore operation.
  126. For data streams, these index settings are applied to the restored backing
  127. indices.
  128. // tag::index-settings-data-stream-warning[]
  129. [IMPORTANT]
  130. ====
  131. The `index_settings` and `ignore_index_settings` parameters affect
  132. restored backing indices only. New backing indices created for a stream use the index
  133. settings specified in the stream's matching
  134. <<create-index-template,index template>>.
  135. If you change index settings during a restore, we recommend you make similar
  136. changes in the stream's matching index template. This ensures new backing
  137. indices created for the stream use the same index settings.
  138. ====
  139. // end::index-settings-data-stream-warning[]
  140. [discrete]
  141. === Restoring to a different cluster
  142. The information stored in a snapshot is not tied to a particular cluster or a cluster name. Therefore, it's possible to
  143. restore a snapshot created from one cluster into another cluster by registering the repository that contains the snapshot in the new cluster and starting the restore process.
  144. The topology of the new cluster does not have to match the cluster where the snapshot was created. However, the version of the new cluster must be the same or only one major version newer than the cluster that was used to create the snapshot. For example, you can restore a 5.x snapshot to a 6.x cluster, but not a 5.x snapshot to a 7.x cluster.
  145. If the new cluster has a smaller capacity, consider the following changes:
  146. * Ensure that the new cluster has enough capacity to store all data streams and indices in the snapshot.
  147. * Change the index settings during the restore operation to reduce the
  148. <<dynamic-index-number-of-replicas,number of replicas>>.
  149. * Use the `indices` parameter to choose only specific data streams or indices to restore.
  150. If indices or backing indices in the original cluster were assigned to particular nodes using
  151. <<shard-allocation-filtering,shard allocation filtering>>, the same rules will be enforced in the new cluster. If the new cluster does not contain nodes with appropriate attributes that a restored index can be allocated on, the
  152. index will not be successfully restored unless these index allocation settings are changed during the restore operation.
  153. The restore operation also checks that restored persistent settings are compatible with the current cluster to avoid accidentally
  154. restoring incompatible settings. If you need to restore a snapshot with incompatible persistent settings, try restoring it without
  155. the <<restore-snapshot-api-include-global-state,global cluster state>>.