restore-snapshot.asciidoc 8.0 KB

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