restore-snapshot.asciidoc 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. Set `include_aliases` to `false` to prevent aliases from being restored together
  61. with associated indices.
  62. [source,console]
  63. -----------------------------------
  64. POST /_snapshot/my_backup/snapshot_1/_restore
  65. {
  66. "indices": "data_stream_1,index_1,index_2",
  67. "ignore_unavailable": true,
  68. "include_global_state": false, <1>
  69. "rename_pattern": "index_(.+)",
  70. "rename_replacement": "restored_index_$1",
  71. "include_aliases": false
  72. }
  73. -----------------------------------
  74. // TEST[continued]
  75. <1> By default, `include_global_state` is `false`, meaning the snapshot's
  76. cluster state and feature states are not restored.
  77. +
  78. If `true`, the snapshot's persistent settings, index templates, ingest
  79. pipelines, and {ilm-init} policies are restored into the current cluster. This
  80. overwrites any existing cluster settings, templates, pipelines and {ilm-init}
  81. policies whose names match those in the snapshot.
  82. The restore operation must be performed on a functioning cluster. However, an
  83. existing index can be only restored if it's <<indices-close,closed>> and
  84. has the same number of shards as the index in the snapshot. The restore
  85. operation automatically opens restored indices if they were closed and creates
  86. new indices if they didn't exist in the cluster.
  87. If a data stream is restored, its backing indices are also restored. The restore
  88. operation automatically opens restored backing indices if they were closed.
  89. In addition to entire data streams, you can restore only specific backing
  90. indices from a snapshot. However, restored backing indices are not automatically
  91. added to any existing data streams. For example, if only the
  92. `.ds-logs-2099.03.08-000003` backing index is restored from a snapshot, it is
  93. not automatically added to the existing `logs` data stream.
  94. [discrete]
  95. === Partial restore
  96. By default, the entire restore operation will fail if one or more indices or backing indices participating in the operation don't have
  97. snapshots of all shards available. It can occur if some shards failed to snapshot for example. It is still possible to
  98. restore such indices by setting `partial` to `true`. Please note, that only successfully snapshotted shards will be
  99. restored in this case and all missing shards will be recreated empty.
  100. [discrete]
  101. [[change-index-settings-during-restore]]
  102. === Changing index settings during restore
  103. Use the <<restore-snapshot-api-index-settings,`index_settings`>> parameter
  104. to override index settings during the restore process. For example, the
  105. following request will restore the index `index_1` without creating any
  106. replicas while switching back to the default refresh interval:
  107. [source,console]
  108. -----------------------------------
  109. POST /_snapshot/my_backup/snapshot_1/_restore
  110. {
  111. "indices": "index_1",
  112. "ignore_unavailable": true,
  113. "index_settings": {
  114. "index.number_of_replicas": 0
  115. },
  116. "ignore_index_settings": [
  117. "index.refresh_interval"
  118. ]
  119. }
  120. -----------------------------------
  121. // TEST[continued]
  122. NOTE: Some settings such as `index.number_of_shards` cannot be changed during the restore operation.
  123. For data streams, these index settings are applied to the restored backing
  124. indices.
  125. // tag::index-settings-data-stream-warning[]
  126. [IMPORTANT]
  127. ====
  128. The `index_settings` and `ignore_index_settings` parameters affect
  129. restored backing indices only. New backing indices created for a stream use the index
  130. settings specified in the stream's matching
  131. <<create-index-template,index template>>.
  132. If you change index settings during a restore, we recommend you make similar
  133. changes in the stream's matching index template. This ensures new backing
  134. indices created for the stream use the same index settings.
  135. ====
  136. // end::index-settings-data-stream-warning[]
  137. [discrete]
  138. === Restoring to a different cluster
  139. The information stored in a snapshot is not tied to a particular cluster or a cluster name. Therefore, it's possible to
  140. 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.
  141. 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.
  142. If the new cluster has a smaller capacity, consider the following changes:
  143. * Ensure that the new cluster has enough capacity to store all data streams and indices in the snapshot.
  144. * Change the index settings during the restore operation to reduce the
  145. <<dynamic-index-number-of-replicas,number of replicas>>.
  146. * Use the `indices` parameter to choose only specific data streams or indices to restore.
  147. If indices or backing indices in the original cluster were assigned to particular nodes using
  148. <<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
  149. index will not be successfully restored unless these index allocation settings are changed during the restore operation.
  150. The restore operation also checks that restored persistent settings are compatible with the current cluster to avoid accidentally
  151. restoring incompatible settings. If you need to restore a snapshot with incompatible persistent settings, try restoring it without
  152. the <<restore-snapshot-api-include-global-state,global cluster state>>.