restore-snapshot.asciidoc 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. [[snapshots-restore-snapshot]]
  2. == Restore indices from a snapshot
  3. ++++
  4. <titleabbrev>Restore a snapshot</titleabbrev>
  5. ++++
  6. ////
  7. [source,console]
  8. -----------------------------------
  9. PUT /_snapshot/my_backup
  10. {
  11. "type": "fs",
  12. "settings": {
  13. "location": "my_backup_location"
  14. }
  15. }
  16. PUT /_snapshot/my_backup/snapshot_1?wait_for_completion=true
  17. -----------------------------------
  18. // TESTSETUP
  19. ////
  20. A snapshot can be restored using the following command:
  21. [source,console]
  22. -----------------------------------
  23. POST /_snapshot/my_backup/snapshot_1/_restore
  24. -----------------------------------
  25. By default, all indices in the snapshot are restored, and the cluster state is
  26. *not* restored. It's possible to select indices that should be restored as well
  27. as to allow the global cluster state from being restored by using `indices` and
  28. `include_global_state` options in the restore request body. The list of indices
  29. supports <<multi-index,multi index syntax>>. The `rename_pattern`
  30. and `rename_replacement` options can be also used to rename indices on restore
  31. using regular expression that supports referencing the original text as
  32. explained
  33. http://docs.oracle.com/javase/6/docs/api/java/util/regex/Matcher.html#appendReplacement(java.lang.StringBuffer,%20java.lang.String)[here].
  34. Set `include_aliases` to `false` to prevent aliases from being restored together
  35. with associated indices
  36. [source,console]
  37. -----------------------------------
  38. POST /_snapshot/my_backup/snapshot_1/_restore
  39. {
  40. "indices": "index_1,index_2",
  41. "ignore_unavailable": true,
  42. "include_global_state": true,
  43. "rename_pattern": "index_(.+)",
  44. "rename_replacement": "restored_index_$1"
  45. }
  46. -----------------------------------
  47. // TEST[continued]
  48. The restore operation can be performed on a functioning cluster. However, an
  49. existing index can be only restored if it's <<indices-open-close,closed>> and
  50. has the same number of shards as the index in the snapshot. The restore
  51. operation automatically opens restored indices if they were closed and creates
  52. new indices if they didn't exist in the cluster. If cluster state is restored
  53. with `include_global_state` (defaults to `false`), the restored templates that
  54. don't currently exist in the cluster are added and existing templates with the
  55. same name are replaced by the restored templates. The restored persistent
  56. settings are added to the existing persistent settings.
  57. [float]
  58. === Partial restore
  59. By default, the entire restore operation will fail if one or more indices participating in the operation don't have
  60. snapshots of all shards available. It can occur if some shards failed to snapshot for example. It is still possible to
  61. restore such indices by setting `partial` to `true`. Please note, that only successfully snapshotted shards will be
  62. restored in this case and all missing shards will be recreated empty.
  63. [float]
  64. === Changing index settings during restore
  65. Most of index settings can be overridden during the restore process. For example, the following command will restore
  66. the index `index_1` without creating any replicas while switching back to default refresh interval:
  67. [source,console]
  68. -----------------------------------
  69. POST /_snapshot/my_backup/snapshot_1/_restore
  70. {
  71. "indices": "index_1",
  72. "ignore_unavailable": true,
  73. "index_settings": {
  74. "index.number_of_replicas": 0
  75. },
  76. "ignore_index_settings": [
  77. "index.refresh_interval"
  78. ]
  79. }
  80. -----------------------------------
  81. // TEST[continued]
  82. Please note, that some settings such as `index.number_of_shards` cannot be changed during restore operation.
  83. [float]
  84. === Restoring to a different cluster
  85. The information stored in a snapshot is not tied to a particular cluster or a cluster name. Therefore it's possible to
  86. restore a snapshot made from one cluster into another cluster. All that is required is registering the repository
  87. containing the snapshot in the new cluster and starting the restore process. The new cluster doesn't have to have the
  88. same size or topology. However, the version of the new cluster should be the same or newer (only 1 major version newer) than the cluster that was used to create the snapshot. For example, you can restore a 1.x snapshot to a 2.x cluster, but not a 1.x snapshot to a 5.x cluster.
  89. If the new cluster has a smaller size additional considerations should be made. First of all it's necessary to make sure
  90. that new cluster have enough capacity to store all indices in the snapshot. It's possible to change indices settings
  91. during restore to reduce the number of replicas, which can help with restoring snapshots into smaller cluster. It's also
  92. possible to select only subset of the indices using the `indices` parameter.
  93. If indices in the original cluster were assigned to particular nodes using
  94. <<shard-allocation-filtering,shard allocation filtering>>, the same rules will be enforced in the new cluster. Therefore
  95. if the new cluster doesn't contain nodes with appropriate attributes that a restored index can be allocated on, such
  96. index will not be successfully restored unless these index allocation settings are changed during restore operation.
  97. The restore operation also checks that restored persistent settings are compatible with the current cluster to avoid accidentally
  98. restoring incompatible settings. If you need to restore a snapshot with incompatible persistent settings, try restoring it without
  99. the global cluster state.
  100. [float]
  101. === Snapshot status
  102. A list of currently running snapshots with their detailed status information can be obtained using the following command:
  103. [source,console]
  104. -----------------------------------
  105. GET /_snapshot/_status
  106. -----------------------------------
  107. // TEST[continued]
  108. In this format, the command will return information about all currently running snapshots. By specifying a repository name, it's possible
  109. to limit the results to a particular repository:
  110. [source,console]
  111. -----------------------------------
  112. GET /_snapshot/my_backup/_status
  113. -----------------------------------
  114. // TEST[continued]
  115. If both repository name and snapshot id are specified, this command will return detailed status information for the given snapshot even
  116. if it's not currently running:
  117. [source,console]
  118. -----------------------------------
  119. GET /_snapshot/my_backup/snapshot_1/_status
  120. -----------------------------------
  121. // TEST[continued]
  122. The output looks similar to the following:
  123. [source,console-result]
  124. --------------------------------------------------
  125. {
  126. "snapshots": [
  127. {
  128. "snapshot": "snapshot_1",
  129. "repository": "my_backup",
  130. "uuid": "XuBo4l4ISYiVg0nYUen9zg",
  131. "state": "SUCCESS",
  132. "include_global_state": true,
  133. "shards_stats": {
  134. "initializing": 0,
  135. "started": 0,
  136. "finalizing": 0,
  137. "done": 5,
  138. "failed": 0,
  139. "total": 5
  140. },
  141. "stats": {
  142. "incremental": {
  143. "file_count": 8,
  144. "size_in_bytes": 4704
  145. },
  146. "processed": {
  147. "file_count": 7,
  148. "size_in_bytes": 4254
  149. },
  150. "total": {
  151. "file_count": 8,
  152. "size_in_bytes": 4704
  153. },
  154. "start_time_in_millis": 1526280280355,
  155. "time_in_millis": 358
  156. }
  157. }
  158. ]
  159. }
  160. --------------------------------------------------
  161. // TESTRESPONSE[skip: No snapshot status to validate.]
  162. The output is composed of different sections. The `stats` sub-object provides details on the number and size of files that were
  163. snapshotted. As snapshots are incremental, copying only the Lucene segments that are not already in the repository,
  164. the `stats` object contains a `total` section for all the files that are referenced by the snapshot, as well as an `incremental` section
  165. for those files that actually needed to be copied over as part of the incremental snapshotting. In case of a snapshot that's still
  166. in progress, there's also a `processed` section that contains information about the files that are in the process of being copied.
  167. Multiple ids are also supported:
  168. [source,console]
  169. -----------------------------------
  170. GET /_snapshot/my_backup/snapshot_1,snapshot_2/_status
  171. -----------------------------------
  172. // TEST[skip: no snapshot_2 to get]