snapshots.asciidoc 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. [[modules-snapshots]]
  2. == Snapshot And Restore
  3. // tag::snapshot-intro[]
  4. A snapshot is a backup taken from a running Elasticsearch cluster. You can take
  5. a snapshot of individual indices or of the entire cluster and store it in a
  6. repository on a shared filesystem, and there are plugins that support remote
  7. repositories on S3, HDFS, Azure, Google Cloud Storage and more.
  8. Snapshots are taken incrementally. This means that when it creates a snapshot of
  9. an index, Elasticsearch avoids copying any data that is already stored in the
  10. repository as part of an earlier snapshot of the same index. Therefore it can be
  11. efficient to take snapshots of your cluster quite frequently.
  12. // end::snapshot-intro[]
  13. // tag::restore-intro[]
  14. You can restore snapshots into a running cluster via the
  15. <<restore-snapshot,restore API>>. When you restore an index, you can alter the
  16. name of the restored index as well as some of its settings. There is a great
  17. deal of flexibility in how the snapshot and restore functionality can be used.
  18. // end::restore-intro[]
  19. You can automate your snapshot backup and restore process by using
  20. <<getting-started-snapshot-lifecycle-management, snapshot lifecycle management>>.
  21. // tag::backup-warning[]
  22. WARNING: You cannot back up an Elasticsearch cluster by simply taking a copy of
  23. the data directories of all of its nodes. Elasticsearch may be making changes to
  24. the contents of its data directories while it is running; copying its data
  25. directories cannot be expected to capture a consistent picture of their contents.
  26. If you try to restore a cluster from such a backup, it may fail and report
  27. corruption and/or missing files. Alternatively, it may appear to have succeeded
  28. though it silently lost some of its data. The only reliable way to back up a
  29. cluster is by using the snapshot and restore functionality.
  30. // end::backup-warning[]
  31. [float]
  32. === Version compatibility
  33. IMPORTANT: Version compatibility refers to the underlying Lucene index
  34. compatibility. Follow the <<setup-upgrade,Upgrade documentation>>
  35. when migrating between versions.
  36. A snapshot contains a copy of the on-disk data structures that make up an
  37. index. This means that snapshots can only be restored to versions of
  38. Elasticsearch that can read the indices:
  39. * A snapshot of an index created in 6.x can be restored to 7.x.
  40. * A snapshot of an index created in 5.x can be restored to 6.x.
  41. * A snapshot of an index created in 2.x can be restored to 5.x.
  42. * A snapshot of an index created in 1.x can be restored to 2.x.
  43. Conversely, snapshots of indices created in 1.x **cannot** be restored to 5.x
  44. or 6.x, snapshots of indices created in 2.x **cannot** be restored to 6.x
  45. or 7.x, and snapshots of indices created in 5.x **cannot** be restored to 7.x
  46. or 8.x.
  47. Each snapshot can contain indices created in various versions of Elasticsearch,
  48. and when restoring a snapshot it must be possible to restore all of the indices
  49. into the target cluster. If any indices in a snapshot were created in an
  50. incompatible version, you will not be able restore the snapshot.
  51. IMPORTANT: When backing up your data prior to an upgrade, keep in mind that you
  52. won't be able to restore snapshots after you upgrade if they contain indices
  53. created in a version that's incompatible with the upgrade version.
  54. If you end up in a situation where you need to restore a snapshot of an index
  55. that is incompatible with the version of the cluster you are currently running,
  56. you can restore it on the latest compatible version and use
  57. <<reindex-from-remote,reindex-from-remote>> to rebuild the index on the current
  58. version. Reindexing from remote is only possible if the original index has
  59. source enabled. Retrieving and reindexing the data can take significantly
  60. longer than simply restoring a snapshot. If you have a large amount of data, we
  61. recommend testing the reindex from remote process with a subset of your data to
  62. understand the time requirements before proceeding.
  63. [float]
  64. [[snapshots-repositories]]
  65. === Repositories
  66. You must register a snapshot repository before you can perform snapshot and
  67. restore operations. We recommend creating a new snapshot repository for each
  68. major version. The valid repository settings depend on the repository type.
  69. If you register same snapshot repository with multiple clusters, only
  70. one cluster should have write access to the repository. All other clusters
  71. connected to that repository should set the repository to `readonly` mode.
  72. IMPORTANT: The snapshot format can change across major versions, so if you have
  73. clusters on different versions trying to write the same repository, snapshots
  74. written by one version may not be visible to the other and the repository could
  75. be corrupted. While setting the repository to `readonly` on all but one of the
  76. clusters should work with multiple clusters differing by one major version, it
  77. is not a supported configuration.
  78. [source,console]
  79. -----------------------------------
  80. PUT /_snapshot/my_backup
  81. {
  82. "type": "fs",
  83. "settings": {
  84. "location": "my_backup_location"
  85. }
  86. }
  87. -----------------------------------
  88. // TESTSETUP
  89. To retrieve information about a registered repository, use a GET request:
  90. [source,console]
  91. -----------------------------------
  92. GET /_snapshot/my_backup
  93. -----------------------------------
  94. which returns:
  95. [source,console-result]
  96. -----------------------------------
  97. {
  98. "my_backup": {
  99. "type": "fs",
  100. "settings": {
  101. "location": "my_backup_location"
  102. }
  103. }
  104. }
  105. -----------------------------------
  106. To retrieve information about multiple repositories, specify a comma-delimited
  107. list of repositories. You can also use the * wildcard when
  108. specifying repository names. For example, the following request retrieves
  109. information about all of the snapshot repositories that start with `repo` or
  110. contain `backup`:
  111. [source,console]
  112. -----------------------------------
  113. GET /_snapshot/repo*,*backup*
  114. -----------------------------------
  115. To retrieve information about all registered snapshot repositories, omit the
  116. repository name or specify `_all`:
  117. [source,console]
  118. -----------------------------------
  119. GET /_snapshot
  120. -----------------------------------
  121. or
  122. [source,console]
  123. -----------------------------------
  124. GET /_snapshot/_all
  125. -----------------------------------
  126. [float]
  127. ===== Shared File System Repository
  128. The shared file system repository (`"type": "fs"`) uses the shared file system to store snapshots. In order to register
  129. the shared file system repository it is necessary to mount the same shared filesystem to the same location on all
  130. master and data nodes. This location (or one of its parent directories) must be registered in the `path.repo`
  131. setting on all master and data nodes.
  132. Assuming that the shared filesystem is mounted to `/mount/backups/my_fs_backup_location`, the following setting should
  133. be added to `elasticsearch.yml` file:
  134. [source,yaml]
  135. --------------
  136. path.repo: ["/mount/backups", "/mount/longterm_backups"]
  137. --------------
  138. The `path.repo` setting supports Microsoft Windows UNC paths as long as at least server name and share are specified as
  139. a prefix and back slashes are properly escaped:
  140. [source,yaml]
  141. --------------
  142. path.repo: ["\\\\MY_SERVER\\Snapshots"]
  143. --------------
  144. After all nodes are restarted, the following command can be used to register the shared file system repository with
  145. the name `my_fs_backup`:
  146. [source,console]
  147. -----------------------------------
  148. PUT /_snapshot/my_fs_backup
  149. {
  150. "type": "fs",
  151. "settings": {
  152. "location": "/mount/backups/my_fs_backup_location",
  153. "compress": true
  154. }
  155. }
  156. -----------------------------------
  157. // TEST[skip:no access to absolute path]
  158. If the repository location is specified as a relative path this path will be resolved against the first path specified
  159. in `path.repo`:
  160. [source,console]
  161. -----------------------------------
  162. PUT /_snapshot/my_fs_backup
  163. {
  164. "type": "fs",
  165. "settings": {
  166. "location": "my_fs_backup_location",
  167. "compress": true
  168. }
  169. }
  170. -----------------------------------
  171. // TEST[continued]
  172. The following settings are supported:
  173. [horizontal]
  174. `location`:: Location of the snapshots. Mandatory.
  175. `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`.
  176. `chunk_size`:: Big files can be broken down into chunks during snapshotting if needed. Specify the chunk size as a value and
  177. unit, for example: `1GB`, `10MB`, `5KB`, `500B`. Defaults to `null` (unlimited chunk size).
  178. `max_restore_bytes_per_sec`:: Throttles per node restore rate. Defaults to `40mb` per second.
  179. `max_snapshot_bytes_per_sec`:: Throttles per node snapshot rate. Defaults to `40mb` per second.
  180. `readonly`:: Makes repository read-only. Defaults to `false`.
  181. [float]
  182. ===== Read-only URL Repository
  183. The URL repository (`"type": "url"`) can be used as an alternative read-only way to access data created by the shared file
  184. system repository. The URL specified in the `url` parameter should point to the root of the shared filesystem repository.
  185. The following settings are supported:
  186. [horizontal]
  187. `url`:: Location of the snapshots. Mandatory.
  188. URL Repository supports the following protocols: "http", "https", "ftp", "file" and "jar". URL repositories with `http:`,
  189. `https:`, and `ftp:` URLs has to be whitelisted by specifying allowed URLs in the `repositories.url.allowed_urls` setting.
  190. This setting supports wildcards in the place of host, path, query, and fragment. For example:
  191. [source,yaml]
  192. -----------------------------------
  193. repositories.url.allowed_urls: ["http://www.example.org/root/*", "https://*.mydomain.com/*?*#*"]
  194. -----------------------------------
  195. URL repositories with `file:` URLs can only point to locations registered in the `path.repo` setting similar to
  196. shared file system repository.
  197. [float]
  198. [role="xpack"]
  199. [testenv="basic"]
  200. ===== Source Only Repository
  201. A source repository enables you to create minimal, source-only snapshots that take up to 50% less space on disk.
  202. Source only snapshots contain stored fields and index metadata. They do not include index or doc values structures
  203. and are not searchable when restored. After restoring a source-only snapshot, you must <<docs-reindex,reindex>>
  204. the data into a new index.
  205. Source repositories delegate to another snapshot repository for storage.
  206. [IMPORTANT]
  207. ==================================================
  208. Source only snapshots are only supported if the `_source` field is enabled and no source-filtering is applied.
  209. When you restore a source only snapshot:
  210. * The restored index is read-only and can only serve `match_all` search or scroll requests to enable reindexing.
  211. * Queries other than `match_all` and `_get` requests are not supported.
  212. * The mapping of the restored index is empty, but the original mapping is available from the types top
  213. level `meta` element.
  214. ==================================================
  215. When you create a source repository, you must specify the type and name of the delegate repository
  216. where the snapshots will be stored:
  217. [source,console]
  218. -----------------------------------
  219. PUT _snapshot/my_src_only_repository
  220. {
  221. "type": "source",
  222. "settings": {
  223. "delegate_type": "fs",
  224. "location": "my_backup_location"
  225. }
  226. }
  227. -----------------------------------
  228. // TEST[continued]
  229. [float]
  230. ===== Repository plugins
  231. Other repository backends are available in these official plugins:
  232. * {plugins}/repository-s3.html[repository-s3] for S3 repository support
  233. * {plugins}/repository-hdfs.html[repository-hdfs] for HDFS repository support in Hadoop environments
  234. * {plugins}/repository-azure.html[repository-azure] for Azure storage repositories
  235. * {plugins}/repository-gcs.html[repository-gcs] for Google Cloud Storage repositories
  236. [float]
  237. ===== Repository Verification
  238. When a repository is registered, it's immediately verified on all master and data nodes to make sure that it is functional
  239. on all nodes currently present in the cluster. The `verify` parameter can be used to explicitly disable the repository
  240. verification when registering or updating a repository:
  241. [source,console]
  242. -----------------------------------
  243. PUT /_snapshot/my_unverified_backup?verify=false
  244. {
  245. "type": "fs",
  246. "settings": {
  247. "location": "my_unverified_backup_location"
  248. }
  249. }
  250. -----------------------------------
  251. // TEST[continued]
  252. The verification process can also be executed manually by running the following command:
  253. [source,console]
  254. -----------------------------------
  255. POST /_snapshot/my_unverified_backup/_verify
  256. -----------------------------------
  257. // TEST[continued]
  258. It returns a list of nodes where repository was successfully verified or an error message if verification process failed.
  259. [float]
  260. ===== Repository Cleanup
  261. Repositories can over time accumulate data that is not referenced by any existing snapshot. This is a result of the data safety guarantees
  262. the snapshot functionality provides in failure scenarios during snapshot creation and the decentralized nature of the snapshot creation
  263. process. This unreferenced data does in no way negatively impact the performance or safety of a snapshot repository but leads to higher
  264. than necessary storage use. In order to clean up this unreferenced data, users can call the cleanup endpoint for a repository which will
  265. trigger a complete accounting of the repositories contents and subsequent deletion of all unreferenced data that was found.
  266. [source,console]
  267. -----------------------------------
  268. POST /_snapshot/my_repository/_cleanup
  269. -----------------------------------
  270. // TEST[continued]
  271. The response to a cleanup request looks as follows:
  272. [source,console-result]
  273. --------------------------------------------------
  274. {
  275. "results": {
  276. "deleted_bytes": 20,
  277. "deleted_blobs": 5
  278. }
  279. }
  280. --------------------------------------------------
  281. Depending on the concrete repository implementation the numbers shown for bytes free as well as the number of blobs removed will either
  282. be an approximation or an exact result. Any non-zero value for the number of blobs removed implies that unreferenced blobs were found and
  283. subsequently cleaned up.
  284. Please note that most of the cleanup operations executed by this endpoint are automatically executed when deleting any snapshot from a
  285. repository. If you regularly delete snapshots, you will in most cases not get any or only minor space savings from using this functionality
  286. and should lower your frequency of invoking it accordingly.
  287. [float]
  288. [[snapshots-take-snapshot]]
  289. === Snapshot
  290. A repository can contain multiple snapshots of the same cluster. Snapshots are identified by unique names within the
  291. cluster. A snapshot with the name `snapshot_1` in the repository `my_backup` can be created by executing the following
  292. command:
  293. [source,console]
  294. -----------------------------------
  295. PUT /_snapshot/my_backup/snapshot_1?wait_for_completion=true
  296. -----------------------------------
  297. // TEST[continued]
  298. The `wait_for_completion` parameter specifies whether or not the request should return immediately after snapshot
  299. initialization (default) or wait for snapshot completion. During snapshot initialization, information about all
  300. previous snapshots is loaded into the memory, which means that in large repositories it may take several seconds (or
  301. even minutes) for this command to return even if the `wait_for_completion` parameter is set to `false`.
  302. By default a snapshot of all open and started indices in the cluster is created. This behavior can be changed by
  303. specifying the list of indices in the body of the snapshot request.
  304. [source,console]
  305. -----------------------------------
  306. PUT /_snapshot/my_backup/snapshot_2?wait_for_completion=true
  307. {
  308. "indices": "index_1,index_2",
  309. "ignore_unavailable": true,
  310. "include_global_state": false,
  311. "metadata": {
  312. "taken_by": "kimchy",
  313. "taken_because": "backup before upgrading"
  314. }
  315. }
  316. -----------------------------------
  317. // TEST[continued]
  318. The list of indices that should be included into the snapshot can be specified using the `indices` parameter that
  319. supports <<multi-index,multi index syntax>>. The snapshot request also supports the
  320. `ignore_unavailable` option. Setting it to `true` will cause indices that do not exist to be ignored during snapshot
  321. creation. By default, when `ignore_unavailable` option is not set and an index is missing the snapshot request will fail.
  322. By setting `include_global_state` to false it's possible to prevent the cluster global state to be stored as part of
  323. the snapshot. By default, the entire snapshot will fail if one or more indices participating in the snapshot don't have
  324. all primary shards available. This behaviour can be changed by setting `partial` to `true`.
  325. The `metadata` field can be used to attach arbitrary metadata to the snapshot. This may be a record of who took the snapshot,
  326. why it was taken, or any other data that might be useful.
  327. Snapshot names can be automatically derived using <<date-math-index-names,date math expressions>>, similarly as when creating
  328. new indices. Note that special characters need to be URI encoded.
  329. For example, creating a snapshot with the current day in the name, like `snapshot-2018.05.11`, can be achieved with
  330. the following command:
  331. [source,console]
  332. -----------------------------------
  333. # PUT /_snapshot/my_backup/<snapshot-{now/d}>
  334. PUT /_snapshot/my_backup/%3Csnapshot-%7Bnow%2Fd%7D%3E
  335. -----------------------------------
  336. // TEST[continued]
  337. The index snapshot process is incremental. In the process of making the index snapshot Elasticsearch analyses
  338. the list of the index files that are already stored in the repository and copies only files that were created or
  339. changed since the last snapshot. That allows multiple snapshots to be preserved in the repository in a compact form.
  340. Snapshotting process is executed in non-blocking fashion. All indexing and searching operation can continue to be
  341. executed against the index that is being snapshotted. However, a snapshot represents the point-in-time view of the index
  342. at the moment when snapshot was created, so no records that were added to the index after the snapshot process was started
  343. will be present in the snapshot. The snapshot process starts immediately for the primary shards that has been started
  344. and are not relocating at the moment. Before version 1.2.0, the snapshot operation fails if the cluster has any relocating or
  345. initializing primaries of indices participating in the snapshot. Starting with version 1.2.0, Elasticsearch waits for
  346. relocation or initialization of shards to complete before snapshotting them.
  347. Besides creating a copy of each index the snapshot process can also store global cluster metadata, which includes persistent
  348. cluster settings and templates. The transient settings and registered snapshot repositories are not stored as part of
  349. the snapshot.
  350. Only one snapshot process can be executed in the cluster at any time. While snapshot of a particular shard is being
  351. created this shard cannot be moved to another node, which can interfere with rebalancing process and allocation
  352. filtering. Elasticsearch will only be able to move a shard to another node (according to the current allocation
  353. filtering settings and rebalancing algorithm) once the snapshot is finished.
  354. Once a snapshot is created information about this snapshot can be obtained using the following command:
  355. [source,console]
  356. -----------------------------------
  357. GET /_snapshot/my_backup/snapshot_1
  358. -----------------------------------
  359. // TEST[continued]
  360. This command returns basic information about the snapshot including start and end time, version of
  361. Elasticsearch that created the snapshot, the list of included indices, the current state of the
  362. snapshot and the list of failures that occurred during the snapshot. The snapshot `state` can be
  363. [horizontal]
  364. `IN_PROGRESS`::
  365. The snapshot is currently running.
  366. `SUCCESS`::
  367. The snapshot finished and all shards were stored successfully.
  368. `FAILED`::
  369. The snapshot finished with an error and failed to store any data.
  370. `PARTIAL`::
  371. The global cluster state was stored, but data of at least one shard wasn't stored successfully.
  372. The `failure` section in this case should contain more detailed information about shards
  373. that were not processed correctly.
  374. `INCOMPATIBLE`::
  375. The snapshot was created with an old version of Elasticsearch and therefore is incompatible with
  376. the current version of the cluster.
  377. Similar as for repositories, information about multiple snapshots can be queried in one go, supporting wildcards as well:
  378. [source,console]
  379. -----------------------------------
  380. GET /_snapshot/my_backup/snapshot_*,some_other_snapshot
  381. -----------------------------------
  382. // TEST[continued]
  383. All snapshots currently stored in the repository can be listed using the following command:
  384. [source,console]
  385. -----------------------------------
  386. GET /_snapshot/my_backup/_all
  387. -----------------------------------
  388. // TEST[continued]
  389. The command fails if some of the snapshots are unavailable. The boolean parameter `ignore_unavailable` can be used to
  390. return all snapshots that are currently available.
  391. Getting all snapshots in the repository can be costly on cloud-based repositories,
  392. both from a cost and performance perspective. If the only information required is
  393. the snapshot names/uuids in the repository and the indices in each snapshot, then
  394. the optional boolean parameter `verbose` can be set to `false` to execute a more
  395. performant and cost-effective retrieval of the snapshots in the repository. Note
  396. that setting `verbose` to `false` will omit all other information about the snapshot
  397. such as status information, the number of snapshotted shards, etc. The default
  398. value of the `verbose` parameter is `true`.
  399. It is also possible to retrieve snapshots from multiple repositories in one go, for example:
  400. [source,console]
  401. -----------------------------------
  402. GET /_snapshot/_all
  403. GET /_snapshot/my_backup,my_fs_backup
  404. GET /_snapshot/my*/snap*
  405. -----------------------------------
  406. // TEST[skip:no my_fs_backup]
  407. A currently running snapshot can be retrieved using the following command:
  408. [source,console]
  409. -----------------------------------
  410. GET /_snapshot/my_backup/_current
  411. -----------------------------------
  412. // TEST[continued]
  413. A snapshot can be deleted from the repository using the following command:
  414. [source,console]
  415. -----------------------------------
  416. DELETE /_snapshot/my_backup/snapshot_2
  417. -----------------------------------
  418. // TEST[continued]
  419. When a snapshot is deleted from a repository, Elasticsearch deletes all files that are associated with the deleted
  420. snapshot and not used by any other snapshots. If the deleted snapshot operation is executed while the snapshot is being
  421. created the snapshotting process will be aborted and all files created as part of the snapshotting process will be
  422. cleaned. Therefore, the delete snapshot operation can be used to cancel long running snapshot operations that were
  423. started by mistake.
  424. A repository can be unregistered using the following command:
  425. [source,console]
  426. -----------------------------------
  427. DELETE /_snapshot/my_backup
  428. -----------------------------------
  429. // TEST[continued]
  430. When a repository is unregistered, Elasticsearch only removes the reference to the location where the repository is storing
  431. the snapshots. The snapshots themselves are left untouched and in place.
  432. [float]
  433. [[restore-snapshot]]
  434. === Restore
  435. A snapshot can be restored using the following command:
  436. [source,console]
  437. -----------------------------------
  438. POST /_snapshot/my_backup/snapshot_1/_restore
  439. -----------------------------------
  440. // TEST[continued]
  441. By default, all indices in the snapshot are restored, and the cluster state is
  442. *not* restored. It's possible to select indices that should be restored as well
  443. as to allow the global cluster state from being restored by using `indices` and
  444. `include_global_state` options in the restore request body. The list of indices
  445. supports <<multi-index,multi index syntax>>. The `rename_pattern`
  446. and `rename_replacement` options can be also used to rename indices on restore
  447. using regular expression that supports referencing the original text as
  448. explained
  449. http://docs.oracle.com/javase/6/docs/api/java/util/regex/Matcher.html#appendReplacement(java.lang.StringBuffer,%20java.lang.String)[here].
  450. Set `include_aliases` to `false` to prevent aliases from being restored together
  451. with associated indices
  452. [source,console]
  453. -----------------------------------
  454. POST /_snapshot/my_backup/snapshot_1/_restore
  455. {
  456. "indices": "index_1,index_2",
  457. "ignore_unavailable": true,
  458. "include_global_state": true,
  459. "rename_pattern": "index_(.+)",
  460. "rename_replacement": "restored_index_$1"
  461. }
  462. -----------------------------------
  463. // TEST[continued]
  464. The restore operation can be performed on a functioning cluster. However, an
  465. existing index can be only restored if it's <<indices-open-close,closed>> and
  466. has the same number of shards as the index in the snapshot. The restore
  467. operation automatically opens restored indices if they were closed and creates
  468. new indices if they didn't exist in the cluster. If cluster state is restored
  469. with `include_global_state` (defaults to `false`), the restored templates that
  470. don't currently exist in the cluster are added and existing templates with the
  471. same name are replaced by the restored templates. The restored persistent
  472. settings are added to the existing persistent settings.
  473. [float]
  474. ==== Partial restore
  475. By default, the entire restore operation will fail if one or more indices participating in the operation don't have
  476. snapshots of all shards available. It can occur if some shards failed to snapshot for example. It is still possible to
  477. restore such indices by setting `partial` to `true`. Please note, that only successfully snapshotted shards will be
  478. restored in this case and all missing shards will be recreated empty.
  479. [float]
  480. ==== Changing index settings during restore
  481. Most of index settings can be overridden during the restore process. For example, the following command will restore
  482. the index `index_1` without creating any replicas while switching back to default refresh interval:
  483. [source,console]
  484. -----------------------------------
  485. POST /_snapshot/my_backup/snapshot_1/_restore
  486. {
  487. "indices": "index_1",
  488. "index_settings": {
  489. "index.number_of_replicas": 0
  490. },
  491. "ignore_index_settings": [
  492. "index.refresh_interval"
  493. ]
  494. }
  495. -----------------------------------
  496. // TEST[continued]
  497. Please note, that some settings such as `index.number_of_shards` cannot be changed during restore operation.
  498. [float]
  499. ==== Restoring to a different cluster
  500. The information stored in a snapshot is not tied to a particular cluster or a cluster name. Therefore it's possible to
  501. restore a snapshot made from one cluster into another cluster. All that is required is registering the repository
  502. containing the snapshot in the new cluster and starting the restore process. The new cluster doesn't have to have the
  503. 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.
  504. If the new cluster has a smaller size additional considerations should be made. First of all it's necessary to make sure
  505. that new cluster have enough capacity to store all indices in the snapshot. It's possible to change indices settings
  506. during restore to reduce the number of replicas, which can help with restoring snapshots into smaller cluster. It's also
  507. possible to select only subset of the indices using the `indices` parameter.
  508. If indices in the original cluster were assigned to particular nodes using
  509. <<shard-allocation-filtering,shard allocation filtering>>, the same rules will be enforced in the new cluster. Therefore
  510. if the new cluster doesn't contain nodes with appropriate attributes that a restored index can be allocated on, such
  511. index will not be successfully restored unless these index allocation settings are changed during restore operation.
  512. The restore operation also checks that restored persistent settings are compatible with the current cluster to avoid accidentally
  513. restoring incompatible settings. If you need to restore a snapshot with incompatible persistent settings, try restoring it without
  514. the global cluster state.
  515. [float]
  516. === Snapshot status
  517. A list of currently running snapshots with their detailed status information can be obtained using the following command:
  518. [source,console]
  519. -----------------------------------
  520. GET /_snapshot/_status
  521. -----------------------------------
  522. // TEST[continued]
  523. In this format, the command will return information about all currently running snapshots. By specifying a repository name, it's possible
  524. to limit the results to a particular repository:
  525. [source,console]
  526. -----------------------------------
  527. GET /_snapshot/my_backup/_status
  528. -----------------------------------
  529. // TEST[continued]
  530. If both repository name and snapshot id are specified, this command will return detailed status information for the given snapshot even
  531. if it's not currently running:
  532. [source,console]
  533. -----------------------------------
  534. GET /_snapshot/my_backup/snapshot_1/_status
  535. -----------------------------------
  536. // TEST[continued]
  537. The output looks similar to the following:
  538. [source,console-result]
  539. --------------------------------------------------
  540. {
  541. "snapshots": [
  542. {
  543. "snapshot": "snapshot_1",
  544. "repository": "my_backup",
  545. "uuid": "XuBo4l4ISYiVg0nYUen9zg",
  546. "state": "SUCCESS",
  547. "include_global_state": true,
  548. "shards_stats": {
  549. "initializing": 0,
  550. "started": 0,
  551. "finalizing": 0,
  552. "done": 5,
  553. "failed": 0,
  554. "total": 5
  555. },
  556. "stats": {
  557. "incremental": {
  558. "file_count": 8,
  559. "size_in_bytes": 4704
  560. },
  561. "processed": {
  562. "file_count": 7,
  563. "size_in_bytes": 4254
  564. },
  565. "total": {
  566. "file_count": 8,
  567. "size_in_bytes": 4704
  568. },
  569. "start_time_in_millis": 1526280280355,
  570. "time_in_millis": 358
  571. }
  572. }
  573. ]
  574. }
  575. --------------------------------------------------
  576. The output is composed of different sections. The `stats` sub-object provides details on the number and size of files that were
  577. snapshotted. As snapshots are incremental, copying only the Lucene segments that are not already in the repository,
  578. the `stats` object contains a `total` section for all the files that are referenced by the snapshot, as well as an `incremental` section
  579. for those files that actually needed to be copied over as part of the incremental snapshotting. In case of a snapshot that's still
  580. in progress, there's also a `processed` section that contains information about the files that are in the process of being copied.
  581. Multiple ids are also supported:
  582. [source,console]
  583. -----------------------------------
  584. GET /_snapshot/my_backup/snapshot_1,snapshot_2/_status
  585. -----------------------------------
  586. // TEST[continued]
  587. [float]
  588. [[monitor-snapshot-restore-progress]]
  589. === Monitoring snapshot/restore progress
  590. There are several ways to monitor the progress of the snapshot and restores processes while they are running. Both
  591. operations support `wait_for_completion` parameter that would block client until the operation is completed. This is
  592. the simplest method that can be used to get notified about operation completion.
  593. The snapshot operation can be also monitored by periodic calls to the snapshot info:
  594. [source,console]
  595. -----------------------------------
  596. GET /_snapshot/my_backup/snapshot_1
  597. -----------------------------------
  598. // TEST[continued]
  599. Please note that snapshot info operation uses the same resources and thread pool as the snapshot operation. So,
  600. executing a snapshot info operation while large shards are being snapshotted can cause the snapshot info operation to wait
  601. for available resources before returning the result. On very large shards the wait time can be significant.
  602. To get more immediate and complete information about snapshots the snapshot status command can be used instead:
  603. [source,console]
  604. -----------------------------------
  605. GET /_snapshot/my_backup/snapshot_1/_status
  606. -----------------------------------
  607. // TEST[continued]
  608. While snapshot info method returns only basic information about the snapshot in progress, the snapshot status returns
  609. complete breakdown of the current state for each shard participating in the snapshot.
  610. The restore process piggybacks on the standard recovery mechanism of the Elasticsearch. As a result, standard recovery
  611. monitoring services can be used to monitor the state of restore. When restore operation is executed the cluster
  612. typically goes into `red` state. It happens because the restore operation starts with "recovering" primary shards of the
  613. restored indices. During this operation the primary shards become unavailable which manifests itself in the `red` cluster
  614. state. Once recovery of primary shards is completed Elasticsearch is switching to standard replication process that
  615. creates the required number of replicas at this moment cluster switches to the `yellow` state. Once all required replicas
  616. are created, the cluster switches to the `green` states.
  617. The cluster health operation provides only a high level status of the restore process. It's possible to get more
  618. detailed insight into the current state of the recovery process by using <<indices-recovery, index recovery>> and
  619. <<cat-recovery, cat recovery>> APIs.
  620. [float]
  621. === Stopping currently running snapshot and restore operations
  622. The snapshot and restore framework allows running only one snapshot or one restore operation at a time. If a currently
  623. running snapshot was executed by mistake, or takes unusually long, it can be terminated using the snapshot delete operation.
  624. The snapshot delete operation checks if the deleted snapshot is currently running and if it does, the delete operation stops
  625. that snapshot before deleting the snapshot data from the repository.
  626. [source,console]
  627. -----------------------------------
  628. DELETE /_snapshot/my_backup/snapshot_1
  629. -----------------------------------
  630. // TEST[continued]
  631. The restore operation uses the standard shard recovery mechanism. Therefore, any currently running restore operation can
  632. be canceled by deleting indices that are being restored. Please note that data for all deleted indices will be removed
  633. from the cluster as a result of this operation.
  634. [float]
  635. === Effect of cluster blocks on snapshot and restore operations
  636. Many snapshot and restore operations are affected by cluster and index blocks. For example, registering and unregistering
  637. repositories require write global metadata access. The snapshot operation requires that all indices and their metadata as
  638. well as the global metadata were readable. The restore operation requires the global metadata to be writable, however
  639. the index level blocks are ignored during restore because indices are essentially recreated during restore.
  640. Please note that a repository content is not part of the cluster and therefore cluster blocks don't affect internal
  641. repository operations such as listing or deleting snapshots from an already registered repository.