take-snapshot.asciidoc 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. [[snapshots-take-snapshot]]
  2. == Take a snapshot of one or more indices
  3. ++++
  4. <titleabbrev>Take a snapshot</titleabbrev>
  5. ++++
  6. A repository can contain multiple snapshots of the same cluster. Snapshots are identified by unique names within the
  7. cluster. A snapshot with the name `snapshot_1` in the repository `my_backup` can be created by executing the following
  8. command:
  9. ////
  10. [source,console]
  11. -----------------------------------
  12. PUT /_snapshot/my_backup
  13. {
  14. "type": "fs",
  15. "settings": {
  16. "location": "my_backup_location"
  17. }
  18. }
  19. -----------------------------------
  20. // TESTSETUP
  21. ////
  22. [source,console]
  23. -----------------------------------
  24. PUT /_snapshot/my_backup/snapshot_1?wait_for_completion=true
  25. -----------------------------------
  26. The `wait_for_completion` parameter specifies whether or not the request should return immediately after snapshot
  27. initialization (default) or wait for snapshot completion. During snapshot initialization, information about all
  28. previous snapshots is loaded into the memory, which means that in large repositories it may take several seconds (or
  29. even minutes) for this command to return even if the `wait_for_completion` parameter is set to `false`.
  30. By default a snapshot of all open and started indices in the cluster is created. This behavior can be changed by
  31. specifying the list of indices in the body of the snapshot request.
  32. [source,console]
  33. -----------------------------------
  34. PUT /_snapshot/my_backup/snapshot_2?wait_for_completion=true
  35. {
  36. "indices": "index_1,index_2",
  37. "ignore_unavailable": true,
  38. "include_global_state": false,
  39. "metadata": {
  40. "taken_by": "kimchy",
  41. "taken_because": "backup before upgrading"
  42. }
  43. }
  44. -----------------------------------
  45. // TEST[skip:cannot complete subsequent snapshot]
  46. The list of indices that should be included into the snapshot can be specified using the `indices` parameter that
  47. supports <<multi-index,multi index syntax>>. The snapshot request also supports the
  48. `ignore_unavailable` option. Setting it to `true` will cause indices that do not exist to be ignored during snapshot
  49. creation. By default, when `ignore_unavailable` option is not set and an index is missing the snapshot request will fail.
  50. By setting `include_global_state` to false it's possible to prevent the cluster global state to be stored as part of
  51. the snapshot. By default, the entire snapshot will fail if one or more indices participating in the snapshot don't have
  52. all primary shards available. This behaviour can be changed by setting `partial` to `true`.
  53. The `metadata` field can be used to attach arbitrary metadata to the snapshot. This may be a record of who took the snapshot,
  54. why it was taken, or any other data that might be useful.
  55. Snapshot names can be automatically derived using <<date-math-index-names,date math expressions>>, similarly as when creating
  56. new indices. Note that special characters need to be URI encoded.
  57. For example, creating a snapshot with the current day in the name, like `snapshot-2018.05.11`, can be achieved with
  58. the following command:
  59. [source,console]
  60. -----------------------------------
  61. # PUT /_snapshot/my_backup/<snapshot-{now/d}>
  62. PUT /_snapshot/my_backup/%3Csnapshot-%7Bnow%2Fd%7D%3E
  63. -----------------------------------
  64. // TEST[continued]
  65. The index snapshot process is incremental. In the process of making the index snapshot Elasticsearch analyses
  66. the list of the index files that are already stored in the repository and copies only files that were created or
  67. changed since the last snapshot. That allows multiple snapshots to be preserved in the repository in a compact form.
  68. Snapshotting process is executed in non-blocking fashion. All indexing and searching operation can continue to be
  69. executed against the index that is being snapshotted. However, a snapshot represents the point-in-time view of the index
  70. at the moment when snapshot was created, so no records that were added to the index after the snapshot process was started
  71. will be present in the snapshot. The snapshot process starts immediately for the primary shards that has been started
  72. and are not relocating at the moment. Before version 1.2.0, the snapshot operation fails if the cluster has any relocating or
  73. initializing primaries of indices participating in the snapshot. Starting with version 1.2.0, Elasticsearch waits for
  74. relocation or initialization of shards to complete before snapshotting them.
  75. Besides creating a copy of each index the snapshot process can also store global cluster metadata, which includes persistent
  76. cluster settings and templates. The transient settings and registered snapshot repositories are not stored as part of
  77. the snapshot.
  78. Only one snapshot process can be executed in the cluster at any time. While snapshot of a particular shard is being
  79. created this shard cannot be moved to another node, which can interfere with rebalancing process and allocation
  80. filtering. Elasticsearch will only be able to move a shard to another node (according to the current allocation
  81. filtering settings and rebalancing algorithm) once the snapshot is finished.
  82. Once a snapshot is created information about this snapshot can be obtained using the following command:
  83. [source,console]
  84. -----------------------------------
  85. GET /_snapshot/my_backup/snapshot_1
  86. -----------------------------------
  87. // TEST[continued]
  88. This command returns basic information about the snapshot including start and end time, version of
  89. Elasticsearch that created the snapshot, the list of included indices, the current state of the
  90. snapshot and the list of failures that occurred during the snapshot. The snapshot `state` can be
  91. [horizontal]
  92. `IN_PROGRESS`::
  93. The snapshot is currently running.
  94. `SUCCESS`::
  95. The snapshot finished and all shards were stored successfully.
  96. `FAILED`::
  97. The snapshot finished with an error and failed to store any data.
  98. `PARTIAL`::
  99. The global cluster state was stored, but data of at least one shard wasn't stored successfully.
  100. The `failure` section in this case should contain more detailed information about shards
  101. that were not processed correctly.
  102. `INCOMPATIBLE`::
  103. The snapshot was created with an old version of Elasticsearch and therefore is incompatible with
  104. the current version of the cluster.
  105. Similar as for repositories, information about multiple snapshots can be queried in one go, supporting wildcards as well:
  106. [source,console]
  107. -----------------------------------
  108. GET /_snapshot/my_backup/snapshot_*,some_other_snapshot
  109. -----------------------------------
  110. // TEST[continued]
  111. All snapshots currently stored in the repository can be listed using the following command:
  112. [source,console]
  113. -----------------------------------
  114. GET /_snapshot/my_backup/_all
  115. -----------------------------------
  116. // TEST[continued]
  117. The command fails if some of the snapshots are unavailable. The boolean parameter `ignore_unavailable` can be used to
  118. return all snapshots that are currently available.
  119. Getting all snapshots in the repository can be costly on cloud-based repositories,
  120. both from a cost and performance perspective. If the only information required is
  121. the snapshot names/uuids in the repository and the indices in each snapshot, then
  122. the optional boolean parameter `verbose` can be set to `false` to execute a more
  123. performant and cost-effective retrieval of the snapshots in the repository. Note
  124. that setting `verbose` to `false` will omit all other information about the snapshot
  125. such as status information, the number of snapshotted shards, etc. The default
  126. value of the `verbose` parameter is `true`.
  127. It is also possible to retrieve snapshots from multiple repositories in one go, for example:
  128. [source,console]
  129. -----------------------------------
  130. GET /_snapshot/_all
  131. GET /_snapshot/my_backup,my_fs_backup
  132. GET /_snapshot/my*/snap*
  133. -----------------------------------
  134. // TEST[skip:no my_fs_backup]
  135. A currently running snapshot can be retrieved using the following command:
  136. [source,console]
  137. -----------------------------------
  138. GET /_snapshot/my_backup/_current
  139. -----------------------------------
  140. // TEST[continued]
  141. A snapshot can be deleted from the repository using the following command:
  142. [source,console]
  143. -----------------------------------
  144. DELETE /_snapshot/my_backup/snapshot_2
  145. -----------------------------------
  146. // TEST[continued]
  147. When a snapshot is deleted from a repository, Elasticsearch deletes all files that are associated with the deleted
  148. snapshot and not used by any other snapshots. If the deleted snapshot operation is executed while the snapshot is being
  149. created the snapshotting process will be aborted and all files created as part of the snapshotting process will be
  150. cleaned. Therefore, the delete snapshot operation can be used to cancel long running snapshot operations that were
  151. started by mistake.
  152. It is also possible to delete multiple snapshots from a repository in one go, for example:
  153. [source,console]
  154. -----------------------------------
  155. DELETE /_snapshot/my_backup/my_backup,my_fs_backup
  156. DELETE /_snapshot/my_backup/snap*
  157. -----------------------------------
  158. // TEST[skip:no my_fs_backup]
  159. A repository can be unregistered using the following command:
  160. [source,console]
  161. -----------------------------------
  162. DELETE /_snapshot/my_backup
  163. -----------------------------------
  164. // TEST[continued]
  165. When a repository is unregistered, Elasticsearch only removes the reference to the location where the repository is storing
  166. the snapshots. The snapshots themselves are left untouched and in place.