snapshots.asciidoc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. [[modules-snapshots]]
  2. == Snapshot And Restore
  3. The snapshot and restore module allows to create snapshots of individual indices or an entire cluster into a remote
  4. repository. At the time of the initial release only shared file system repository is supported.
  5. [float]
  6. === Repositories
  7. Before any snapshot or restore operation can be performed a snapshot repository should be registered in
  8. Elasticsearch. The following command registers a shared file system repository with the name `my_backup` that
  9. will use location `/mount/backups/my_backup` to store snapshots.
  10. [source,js]
  11. -----------------------------------
  12. $ curl -XPUT 'http://localhost:9200/_snapshot/my_backup' -d '{
  13. "type": "fs",
  14. "settings": {
  15. "location": "/mount/backups/my_backup",
  16. "compress": true
  17. }
  18. }'
  19. -----------------------------------
  20. Once repository is registered, its information can be obtained using the following command:
  21. [source,js]
  22. -----------------------------------
  23. $ curl -XGET 'http://localhost:9200/_snapshot/my_backup?pretty'
  24. -----------------------------------
  25. [source,js]
  26. -----------------------------------
  27. {
  28. "my_backup" : {
  29. "type" : "fs",
  30. "settings" : {
  31. "compress" : "false",
  32. "location" : "/mount/backups/my_backup"
  33. }
  34. }
  35. }
  36. -----------------------------------
  37. If a repository name is not specified, or `_all` is used as repository name Elasticsearch will return information about
  38. all repositories currently registered in the cluster:
  39. [source,js]
  40. -----------------------------------
  41. $ curl -XGET 'http://localhost:9200/_snapshot'
  42. -----------------------------------
  43. or
  44. [source,js]
  45. -----------------------------------
  46. $ curl -XGET 'http://localhost:9200/_snapshot/_all'
  47. -----------------------------------
  48. [float]
  49. ===== Shared File System Repository
  50. The shared file system repository (`"type": "fs"`) is using shared file system to store snapshot. The path
  51. specified in the `location` parameter should point to the same location in the shared filesystem and be accessible
  52. on all data and master nodes. The following settings are supported:
  53. [horizontal]
  54. `location`:: Location of the snapshots. Mandatory.
  55. `compress`:: Turns on compression of the snapshot files. Defaults to `true`.
  56. `concurrent_streams`:: Throttles the number of streams (per node) preforming snapshot operation. Defaults to `5`
  57. `chunk_size`:: Big files can be broken down into chunks during snapshotting if needed. The chunk size can be specified in bytes or by
  58. using size value notation, i.e. 1g, 10m, 5k. Defaults to `null` (unlimited chunk size).
  59. `max_restore_bytes_per_sec`:: Throttles per node restore rate. Defaults to `20mb` per second.
  60. `max_snapshot_bytes_per_sec`:: Throttles per node snapshot rate. Defaults to `20mb` per second.
  61. [float]
  62. ===== Read-only URL Repository
  63. The URL repository (`"type": "url"`) can be used as an alternative read-only way to access data created by shared file
  64. system repository is using shared file system to store snapshot. The URL specified in the `url` parameter should
  65. point to the root of the shared filesystem repository. The following settings are supported:
  66. [horizontal]
  67. `url`:: Location of the snapshots. Mandatory.
  68. `concurrent_streams`:: Throttles the number of streams (per node) preforming snapshot operation. Defaults to `5`
  69. [float]
  70. ===== Repository plugins
  71. Other repository backends are available in these official plugins:
  72. * https://github.com/elasticsearch/elasticsearch-cloud-aws#s3-repository[AWS Cloud Plugin] for S3 repositories
  73. * https://github.com/elasticsearch/elasticsearch-hadoop/tree/master/repository-hdfs[HDFS Plugin] for Hadoop environments
  74. * https://github.com/elasticsearch/elasticsearch-cloud-azure#azure-repository[Azure Cloud Plugin] for Azure storage repositories
  75. [float]
  76. === Snapshot
  77. A repository can contain multiple snapshots of the same cluster. Snapshot are identified by unique names within the
  78. cluster. A snapshot with the name `snapshot_1` in the repository `my_backup` can be created by executing the following
  79. command:
  80. [source,js]
  81. -----------------------------------
  82. $ curl -XPUT "localhost:9200/_snapshot/my_backup/snapshot_1?wait_for_completion=true"
  83. -----------------------------------
  84. The `wait_for_completion` parameter specifies whether or not the request should return immediately or wait for snapshot
  85. completion. By default snapshot of all open and started indices in the cluster is created. This behavior can be changed
  86. by specifying the list of indices in the body of the snapshot request.
  87. [source,js]
  88. -----------------------------------
  89. $ curl -XPUT "localhost:9200/_snapshot/my_backup/snapshot_1" -d '{
  90. "indices": "index_1,index_2",
  91. "ignore_unavailable": "true",
  92. "include_global_state": false
  93. }'
  94. -----------------------------------
  95. The list of indices that should be included into the snapshot can be specified using the `indices` parameter that
  96. supports <<search-multi-index-type,multi index syntax>>. The snapshot request also supports the
  97. `ignore_unavailable` option. Setting it to `true` will cause indices that do not exists to be ignored during snapshot
  98. creation. By default, when `ignore_unavailable` option is not set and an index is missing the snapshot request will fail.
  99. By setting `include_global_state` to false it's possible to prevent the cluster global state to be stored as part of
  100. the snapshot. By default, entire snapshot will fail if one or more indices participating in the snapshot don't have
  101. all primary shards available. This behaviour can be changed by setting `partial` to `true`.
  102. The index snapshot process is incremental. In the process of making the index snapshot Elasticsearch analyses
  103. the list of the index files that are already stored in the repository and copies only files that were created or
  104. changed since the last snapshot. That allows multiple snapshots to be preserved in the repository in a compact form.
  105. Snapshotting process is executed in non-blocking fashion. All indexing and searching operation can continue to be
  106. executed against the index that is being snapshotted. However, a snapshot represents the point-in-time view of the index
  107. at the moment when snapshot was created, so no records that were added to the index after snapshot process had started
  108. will be present in the snapshot.
  109. Besides creating a copy of each index the snapshot process can also store global cluster metadata, which includes persistent
  110. cluster settings and templates. The transient settings and registered snapshot repositories are not stored as part of
  111. the snapshot.
  112. Only one snapshot process can be executed in the cluster at any time. While snapshot of a particular shard is being
  113. created this shard cannot be moved to another node, which can interfere with rebalancing process and allocation
  114. filtering. Once snapshot of the shard is finished Elasticsearch will be able to move shard to another node according
  115. to the current allocation filtering settings and rebalancing algorithm.
  116. Once a snapshot is created information about this snapshot can be obtained using the following command:
  117. [source,shell]
  118. -----------------------------------
  119. $ curl -XGET "localhost:9200/_snapshot/my_backup/snapshot_1"
  120. -----------------------------------
  121. All snapshots currently stored in the repository can be listed using the following command:
  122. [source,shell]
  123. -----------------------------------
  124. $ curl -XGET "localhost:9200/_snapshot/my_backup/_all"
  125. -----------------------------------
  126. A snapshot can be deleted from the repository using the following command:
  127. [source,shell]
  128. -----------------------------------
  129. $ curl -XDELETE "localhost:9200/_snapshot/my_backup/snapshot_1"
  130. -----------------------------------
  131. When a snapshot is deleted from a repository, Elasticsearch deletes all files that are associated with the deleted
  132. snapshot and not used by any other snapshots. If the deleted snapshot operation is executed while the snapshot is being
  133. created the snapshotting process will be aborted and all files created as part of the snapshotting process will be
  134. cleaned. Therefore, the delete snapshot operation can be used to cancel long running snapshot operations that were
  135. started by mistake.
  136. [float]
  137. === Restore
  138. A snapshot can be restored using the following command:
  139. [source,shell]
  140. -----------------------------------
  141. $ curl -XPOST "localhost:9200/_snapshot/my_backup/snapshot_1/_restore"
  142. -----------------------------------
  143. By default, all indices in the snapshot as well as cluster state are restored. It's possible to select indices that
  144. should be restored as well as prevent global cluster state from being restored by using `indices` and
  145. `include_global_state` options in the restore request body. The list of indices supports
  146. <<search-multi-index-type,multi index syntax>>. The `rename_pattern` and `rename_replacement` options can be also used to
  147. rename index on restore using regular expression that supports referencing the original text as explained
  148. http://docs.oracle.com/javase/6/docs/api/java/util/regex/Matcher.html#appendReplacement(java.lang.StringBuffer,%20java.lang.String)[here].
  149. [source,js]
  150. -----------------------------------
  151. $ curl -XPOST "localhost:9200/_snapshot/my_backup/snapshot_1/_restore" -d '{
  152. "indices": "index_1,index_2",
  153. "ignore_unavailable": "true",
  154. "include_global_state": false,
  155. "rename_pattern": "index_(.+)",
  156. "rename_replacement": "restored_index_$1"
  157. }'
  158. -----------------------------------
  159. The restore operation can be performed on a functioning cluster. However, an existing index can be only restored if it's
  160. closed. The restore operation automatically opens restored indices if they were closed and creates new indices if they
  161. didn't exist in the cluster. If cluster state is restored, the restored templates that don't currently exist in the
  162. cluster are added and existing templates with the same name are replaced by the restored templates. The restored
  163. persistent settings are added to the existing persistent settings.
  164. [float]
  165. === Snapshot status
  166. A list of currently running snapshots with their detailed status information can be obtained using the following command:
  167. [source,shell]
  168. -----------------------------------
  169. $ curl -XGET "localhost:9200/_snapshot/_status"
  170. -----------------------------------
  171. In this format, the command will return information about all currently running snapshots. By specifying a repository name, it's possible
  172. to limit the results to a particular repository:
  173. [source,shell]
  174. -----------------------------------
  175. $ curl -XGET "localhost:9200/_snapshot/my_backup/_status"
  176. -----------------------------------
  177. If both repository name and snapshot id are specified, this command will return detailed status information for the given snapshot even
  178. if it's not currently running:
  179. [source,shell]
  180. -----------------------------------
  181. $ curl -XGET "localhost:9200/_snapshot/my_backup/snapshot_1/_status"
  182. -----------------------------------
  183. Multiple ids are also supported:
  184. [source,shell]
  185. -----------------------------------
  186. $ curl -XGET "localhost:9200/_snapshot/my_backup/snapshot_1,snapshot_2/_status"
  187. -----------------------------------