snapshots.asciidoc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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 was supported, but now a range of
  5. backends are available via officially supported repository plugins.
  6. [float]
  7. === Repositories
  8. Before any snapshot or restore operation can be performed a snapshot repository should be registered in
  9. Elasticsearch. The repository settings are repository-type specific. See below for details.
  10. [source,js]
  11. -----------------------------------
  12. PUT /_snapshot/my_backup
  13. {
  14. "type": "fs",
  15. "settings": {
  16. ... repository specific settings ...
  17. }
  18. }
  19. -----------------------------------
  20. Once a repository is registered, its information can be obtained using the following command:
  21. [source,js]
  22. -----------------------------------
  23. GET /_snapshot/my_backup
  24. -----------------------------------
  25. // AUTOSENSE
  26. which returns:
  27. [source,js]
  28. -----------------------------------
  29. {
  30. "my_backup": {
  31. "type": "fs",
  32. "settings": {
  33. "compress": "true",
  34. "location": "/mount/backups/my_backup"
  35. }
  36. }
  37. }
  38. -----------------------------------
  39. If a repository name is not specified, or `_all` is used as repository name Elasticsearch will return information about
  40. all repositories currently registered in the cluster:
  41. [source,js]
  42. -----------------------------------
  43. GET /_snapshot
  44. -----------------------------------
  45. or
  46. [source,js]
  47. -----------------------------------
  48. GET /_snapshot/_all
  49. -----------------------------------
  50. [float]
  51. ===== Shared File System Repository
  52. The shared file system repository (`"type": "fs"`) uses the shared file system to store snapshots. In order to register
  53. the shared file system repository it is necessary to mount the same shared filesystem to the same location on all
  54. master and data nodes. This location (or one of its parent directories) has to be registered in the `path.repo`
  55. setting on all master and data nodes.
  56. Assuming that the shared filesystem is mounted to `/mount/backups/my_backup`, the following setting should be added to
  57. `elasticsearch.yml` file:
  58. [source,yaml]
  59. --------------
  60. path.repo: ["/mount/backups", "/mount/longterm_backups"]
  61. --------------
  62. After all nodes are restarted, the following command can be used to register the shared file system repository with
  63. the name `my_backup`:
  64. [source,js]
  65. -----------------------------------
  66. $ curl -XPUT 'http://localhost:9200/_snapshot/my_backup' -d '{
  67. "type": "fs",
  68. "settings": {
  69. "location": "/mount/backups/my_backup",
  70. "compress": true
  71. }
  72. }'
  73. -----------------------------------
  74. If the repository location is specified as a relative path this path will be resolved against the first path specified
  75. in `path.repo`:
  76. [source,js]
  77. -----------------------------------
  78. $ curl -XPUT 'http://localhost:9200/_snapshot/my_backup' -d '{
  79. "type": "fs",
  80. "settings": {
  81. "location": "my_backup",
  82. "compress": true
  83. }
  84. }'
  85. -----------------------------------
  86. The following settings are supported:
  87. [horizontal]
  88. `location`:: Location of the snapshots. Mandatory.
  89. `compress`:: Turns on compression of the snapshot files. Compression is applied only to metadata files (index mapping and settings). Data files are not compressed. Defaults to `true`.
  90. `chunk_size`:: Big files can be broken down into chunks during snapshotting if needed. The chunk size can be specified in bytes or by
  91. using size value notation, i.e. 1g, 10m, 5k. Defaults to `null` (unlimited chunk size).
  92. `max_restore_bytes_per_sec`:: Throttles per node restore rate. Defaults to `40mb` per second.
  93. `max_snapshot_bytes_per_sec`:: Throttles per node snapshot rate. Defaults to `40mb` per second.
  94. [float]
  95. ===== Read-only URL Repository
  96. The URL repository (`"type": "url"`) can be used as an alternative read-only way to access data created by the shared file
  97. system repository. The URL specified in the `url` parameter should
  98. point to the root of the shared filesystem repository. The following settings are supported:
  99. [horizontal]
  100. `url`:: Location of the snapshots. Mandatory.
  101. [float]
  102. ===== Repository plugins
  103. Other repository backends are available in these official plugins:
  104. * https://github.com/elasticsearch/elasticsearch-cloud-aws#s3-repository[AWS Cloud Plugin] for S3 repositories
  105. * https://github.com/elasticsearch/elasticsearch-hadoop/tree/master/repository-hdfs[HDFS Plugin] for Hadoop environments
  106. * https://github.com/elasticsearch/elasticsearch-cloud-azure#azure-repository[Azure Cloud Plugin] for Azure storage repositories
  107. [float]
  108. ===== Repository Verification
  109. When a repository is registered, it's immediately verified on all master and data nodes to make sure that it is functional
  110. on all nodes currently present in the cluster. The `verify` parameter can be used to explicitly disable the repository
  111. verification when registering or updating a repository:
  112. [source,js]
  113. -----------------------------------
  114. PUT /_snapshot/s3_repository?verify=false
  115. {
  116. "type": "s3",
  117. "settings": {
  118. "bucket": "my_s3_bucket",
  119. "region": "eu-west-1"
  120. }
  121. }
  122. -----------------------------------
  123. // AUTOSENSE
  124. The verification process can also be executed manually by running the following command:
  125. [source,js]
  126. -----------------------------------
  127. POST /_snapshot/my_backup/_verify
  128. -----------------------------------
  129. // AUTOSENSE
  130. It returns a list of nodes where repository was successfully verified or an error message if verification process failed.
  131. [float]
  132. === Snapshot
  133. A repository can contain multiple snapshots of the same cluster. Snapshot are identified by unique names within the
  134. cluster. A snapshot with the name `snapshot_1` in the repository `my_backup` can be created by executing the following
  135. command:
  136. [source,js]
  137. -----------------------------------
  138. PUT /_snapshot/my_backup/snapshot_1?wait_for_completion=true
  139. -----------------------------------
  140. // AUTOSENSE
  141. The `wait_for_completion` parameter specifies whether or not the request should return immediately after snapshot
  142. initialization (default) or wait for snapshot completion. During snapshot initialization, information about all
  143. previous snapshots is loaded into the memory, which means that in large repositories it may take several seconds (or
  144. even minutes) for this command to return even if the `wait_for_completion` parameter is set to `false`.
  145. By default a snapshot of all open and started indices in the cluster is created. This behavior can be changed by
  146. specifying the list of indices in the body of the snapshot request.
  147. [source,js]
  148. -----------------------------------
  149. PUT /_snapshot/my_backup/snapshot_1
  150. {
  151. "indices": "index_1,index_2",
  152. "ignore_unavailable": "true",
  153. "include_global_state": false
  154. }
  155. -----------------------------------
  156. // AUTOSENSE
  157. The list of indices that should be included into the snapshot can be specified using the `indices` parameter that
  158. supports <<search-multi-index-type,multi index syntax>>. The snapshot request also supports the
  159. `ignore_unavailable` option. Setting it to `true` will cause indices that do not exist to be ignored during snapshot
  160. creation. By default, when `ignore_unavailable` option is not set and an index is missing the snapshot request will fail.
  161. By setting `include_global_state` to false it's possible to prevent the cluster global state to be stored as part of
  162. the snapshot. By default, the entire snapshot will fail if one or more indices participating in the snapshot don't have
  163. all primary shards available. This behaviour can be changed by setting `partial` to `true`.
  164. The index snapshot process is incremental. In the process of making the index snapshot Elasticsearch analyses
  165. the list of the index files that are already stored in the repository and copies only files that were created or
  166. changed since the last snapshot. That allows multiple snapshots to be preserved in the repository in a compact form.
  167. Snapshotting process is executed in non-blocking fashion. All indexing and searching operation can continue to be
  168. executed against the index that is being snapshotted. However, a snapshot represents the point-in-time view of the index
  169. at the moment when snapshot was created, so no records that were added to the index after the snapshot process was started
  170. will be present in the snapshot. The snapshot process starts immediately for the primary shards that has been started
  171. and are not relocating at the moment. Before version 1.2.0, the snapshot operation fails if the cluster has any relocating or
  172. initializing primaries of indices participating in the snapshot. Starting with version 1.2.0, Elasticsearch waits for
  173. relocation or initialization of shards to complete before snapshotting them.
  174. Besides creating a copy of each index the snapshot process can also store global cluster metadata, which includes persistent
  175. cluster settings and templates. The transient settings and registered snapshot repositories are not stored as part of
  176. the snapshot.
  177. Only one snapshot process can be executed in the cluster at any time. While snapshot of a particular shard is being
  178. created this shard cannot be moved to another node, which can interfere with rebalancing process and allocation
  179. filtering. Elasticsearch will only be able to move a shard to another node (according to the current allocation
  180. filtering settings and rebalancing algorithm) once the snapshot is finished.
  181. Once a snapshot is created information about this snapshot can be obtained using the following command:
  182. [source,sh]
  183. -----------------------------------
  184. GET /_snapshot/my_backup/snapshot_1
  185. -----------------------------------
  186. // AUTOSENSE
  187. All snapshots currently stored in the repository can be listed using the following command:
  188. [source,sh]
  189. -----------------------------------
  190. GET /_snapshot/my_backup/_all
  191. -----------------------------------
  192. // AUTOSENSE
  193. coming[2.0] A currently running snapshot can be retrieved using the following command:
  194. [source,sh]
  195. -----------------------------------
  196. $ curl -XGET "localhost:9200/_snapshot/my_backup/_current"
  197. -----------------------------------
  198. A snapshot can be deleted from the repository using the following command:
  199. [source,sh]
  200. -----------------------------------
  201. DELETE /_snapshot/my_backup/snapshot_1
  202. -----------------------------------
  203. // AUTOSENSE
  204. When a snapshot is deleted from a repository, Elasticsearch deletes all files that are associated with the deleted
  205. snapshot and not used by any other snapshots. If the deleted snapshot operation is executed while the snapshot is being
  206. created the snapshotting process will be aborted and all files created as part of the snapshotting process will be
  207. cleaned. Therefore, the delete snapshot operation can be used to cancel long running snapshot operations that were
  208. started by mistake.
  209. A repository can be deleted using the following command:
  210. [source,sh]
  211. -----------------------------------
  212. DELETE /_snapshot/my_backup
  213. -----------------------------------
  214. // AUTOSENSE
  215. When a repository is deleted, Elasticsearch only removes the reference to the location where the repository is storing
  216. the snapshots. The snapshots themselves are left untouched and in place.
  217. [float]
  218. === Restore
  219. A snapshot can be restored using the following command:
  220. [source,sh]
  221. -----------------------------------
  222. POST /_snapshot/my_backup/snapshot_1/_restore
  223. -----------------------------------
  224. // AUTOSENSE
  225. By default, all indices in the snapshot as well as cluster state are restored. It's possible to select indices that
  226. should be restored as well as prevent global cluster state from being restored by using `indices` and
  227. `include_global_state` options in the restore request body. The list of indices supports
  228. <<search-multi-index-type,multi index syntax>>. The `rename_pattern` and `rename_replacement` options can be also used to
  229. rename index on restore using regular expression that supports referencing the original text as explained
  230. http://docs.oracle.com/javase/6/docs/api/java/util/regex/Matcher.html#appendReplacement(java.lang.StringBuffer,%20java.lang.String)[here].
  231. Set `include_aliases` to `false` to prevent aliases from being restored together with associated indices
  232. [source,js]
  233. -----------------------------------
  234. POST /_snapshot/my_backup/snapshot_1/_restore
  235. {
  236. "indices": "index_1,index_2",
  237. "ignore_unavailable": "true",
  238. "include_global_state": false,
  239. "rename_pattern": "index_(.+)",
  240. "rename_replacement": "restored_index_$1"
  241. }
  242. -----------------------------------
  243. // AUTOSENSE
  244. The restore operation can be performed on a functioning cluster. However, an existing index can be only restored if it's
  245. <<indices-open-close,closed>> and has the same number of shards as the index in the snapshot.
  246. The restore operation automatically opens restored indices if they were closed and creates new indices if they
  247. didn't exist in the cluster. If cluster state is restored, the restored templates that don't currently exist in the
  248. cluster are added and existing templates with the same name are replaced by the restored templates. The restored
  249. persistent settings are added to the existing persistent settings.
  250. [float]
  251. ==== Partial restore
  252. By default, the entire restore operation will fail if one or more indices participating in the operation don't have
  253. snapshots of all shards available. It can occur if some shards failed to snapshot for example. It is still possible to
  254. restore such indices by setting `partial` to `true`. Please note, that only successfully snapshotted shards will be
  255. restored in this case and all missing shards will be recreated empty.
  256. [float]
  257. ==== Changing index settings during restore
  258. Most of index settings can be overridden during the restore process. For example, the following command will restore
  259. the index `index_1` without creating any replicas while switching back to default refresh interval:
  260. [source,js]
  261. -----------------------------------
  262. POST /_snapshot/my_backup/snapshot_1/_restore
  263. {
  264. "indices": "index_1",
  265. "index_settings": {
  266. "index.number_of_replicas": 0
  267. },
  268. "ignore_index_settings": [
  269. "index.refresh_interval"
  270. ]
  271. }
  272. -----------------------------------
  273. // AUTOSENSE
  274. Please note, that some settings such as `index.number_of_shards` cannot be changed during restore operation.
  275. [float]
  276. ==== Restoring to a different cluster
  277. The information stored in a snapshot is not tied to a particular cluster or a cluster name. Therefore it's possible to
  278. restore a snapshot made from one cluster into another cluster. All that is required is registering the repository
  279. containing the snapshot in the new cluster and starting the restore process. The new cluster doesn't have to have the
  280. same size or topology. However, the version of the new cluster should be the same or newer than the cluster that was
  281. used to create the snapshot.
  282. If the new cluster has a smaller size additional considerations should be made. First of all it's necessary to make sure
  283. that new cluster have enough capacity to store all indices in the snapshot. It's possible to change indices settings
  284. during restore to reduce the number of replicas, which can help with restoring snapshots into smaller cluster. It's also
  285. possible to select only subset of the indices using the `indices` parameter. Prior to version 1.5.0 elasticsearch
  286. didn't check restored persistent settings making it possible to accidentally restore an incompatible
  287. `discovery.zen.minimum_master_nodes` setting, and as a result disable a smaller cluster until the required number of
  288. master eligible nodes is added. Starting with version 1.5.0 incompatible settings are ignored.
  289. If indices in the original cluster were assigned to particular nodes using
  290. <<shard-allocation-filtering,shard allocation filtering>>, the same rules will be enforced in the new cluster. Therefore
  291. if the new cluster doesn't contain nodes with appropriate attributes that a restored index can be allocated on, such
  292. index will not be successfully restored unless these index allocation settings are changed during restore operation.
  293. [float]
  294. === Snapshot status
  295. A list of currently running snapshots with their detailed status information can be obtained using the following command:
  296. [source,sh]
  297. -----------------------------------
  298. GET /_snapshot/_status
  299. -----------------------------------
  300. // AUTOSENSE
  301. In this format, the command will return information about all currently running snapshots. By specifying a repository name, it's possible
  302. to limit the results to a particular repository:
  303. [source,sh]
  304. -----------------------------------
  305. GET /_snapshot/my_backup/_status
  306. -----------------------------------
  307. // AUTOSENSE
  308. If both repository name and snapshot id are specified, this command will return detailed status information for the given snapshot even
  309. if it's not currently running:
  310. [source,sh]
  311. -----------------------------------
  312. GET /_snapshot/my_backup/snapshot_1/_status
  313. -----------------------------------
  314. // AUTOSENSE
  315. Multiple ids are also supported:
  316. [source,sh]
  317. -----------------------------------
  318. GET /_snapshot/my_backup/snapshot_1,snapshot_2/_status
  319. -----------------------------------
  320. // AUTOSENSE
  321. [float]
  322. === Monitoring snapshot/restore progress
  323. There are several ways to monitor the progress of the snapshot and restores processes while they are running. Both
  324. operations support `wait_for_completion` parameter that would block client until the operation is completed. This is
  325. the simplest method that can be used to get notified about operation completion.
  326. The snapshot operation can be also monitored by periodic calls to the snapshot info:
  327. [source,sh]
  328. -----------------------------------
  329. GET /_snapshot/my_backup/snapshot_1
  330. -----------------------------------
  331. // AUTOSENSE
  332. Please note that snapshot info operation uses the same resources and thread pool as the snapshot operation. So,
  333. executing a snapshot info operation while large shards are being snapshotted can cause the snapshot info operation to wait
  334. for available resources before returning the result. On very large shards the wait time can be significant.
  335. To get more immediate and complete information about snapshots the snapshot status command can be used instead:
  336. [source,sh]
  337. -----------------------------------
  338. GET /_snapshot/my_backup/snapshot_1/_status
  339. -----------------------------------
  340. // AUTOSENSE
  341. While snapshot info method returns only basic information about the snapshot in progress, the snapshot status returns
  342. complete breakdown of the current state for each shard participating in the snapshot.
  343. The restore process piggybacks on the standard recovery mechanism of the Elasticsearch. As a result, standard recovery
  344. monitoring services can be used to monitor the state of restore. When restore operation is executed the cluster
  345. typically goes into `red` state. It happens because the restore operation starts with "recovering" primary shards of the
  346. restored indices. During this operation the primary shards become unavailable which manifests itself in the `red` cluster
  347. state. Once recovery of primary shards is completed Elasticsearch is switching to standard replication process that
  348. creates the required number of replicas at this moment cluster switches to the `yellow` state. Once all required replicas
  349. are created, the cluster switches to the `green` states.
  350. The cluster health operation provides only a high level status of the restore process. It’s possible to get more
  351. detailed insight into the current state of the recovery process by using <<indices-recovery, indices recovery>> and
  352. <<cat-recovery, cat recovery>> APIs.
  353. [float]
  354. === Stopping currently running snapshot and restore operations
  355. The snapshot and restore framework allows running only one snapshot or one restore operation at a time. If a currently
  356. running snapshot was executed by mistake, or takes unusually long, it can be terminated using the snapshot delete operation.
  357. The snapshot delete operation checks if the deleted snapshot is currently running and if it does, the delete operation stops
  358. that snapshot before deleting the snapshot data from the repository.
  359. The restore operation uses the standard shard recovery mechanism. Therefore, any currently running restore operation can
  360. be canceled by deleting indices that are being restored. Please note that data for all deleted indices will be removed
  361. from the cluster as a result of this operation.
  362. [float]
  363. === Effect of cluster blocks on snapshot and restore operations
  364. Many snapshot and restore operations are affected by cluster and index blocks. For example, registering and unregistering
  365. repositories require write global metadata access. The snapshot operation requires that all indices and their metadata as
  366. well as the global metadata were readable. The restore operation requires the global metadata to be writable, however
  367. the index level blocks are ignored during restore because indices are essentially recreated during restore.
  368. Please note that a repository content is not part of the cluster and therefore cluster blocks don't affect internal
  369. repository operations such as listing or deleting snapshots from an already registered repository.