snapshots.asciidoc 23 KB

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