restore-snapshot.asciidoc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. [[snapshots-restore-snapshot]]
  2. == Restore a snapshot
  3. This guide shows you how to restore a snapshot. Snapshots are a convenient way
  4. to store a copy of your data outside of a cluster. You can restore a snapshot
  5. to recover indices and data streams after deletion or a hardware failure. You
  6. can also use snapshots to transfer data between clusters.
  7. In this guide, you'll learn how to:
  8. * Get a list of available snapshots
  9. * Restore an index or data stream from a snapshot
  10. * Restore a feature state
  11. * Restore an entire cluster
  12. * Monitor the restore operation
  13. * Cancel an ongoing restore
  14. This guide also provides tips for <<restore-different-cluster,restoring to
  15. another cluster>> and <<troubleshoot-restore,troubleshooting common restore
  16. errors>>.
  17. [discrete]
  18. [[restore-snapshot-prereqs]]
  19. === Prerequisites
  20. include::apis/restore-snapshot-api.asciidoc[tag=restore-prereqs]
  21. [discrete]
  22. [[restore-snapshot-considerations]]
  23. === Considerations
  24. When restoring data from a snapshot, keep the following in mind:
  25. * If you restore a data stream, you also restore its backing indices.
  26. * You can only restore an existing index if it's <<indices-close,closed>> and
  27. the index in the snapshot has the same number of primary shards.
  28. * You can't restore an existing open index. This includes
  29. backing indices for a data stream.
  30. * The restore operation automatically opens restored indices, including backing
  31. indices.
  32. * You can restore only a specific backing index from a data stream. However, the
  33. restore operation doesn't add the restored backing index to any existing data
  34. stream.
  35. [discrete]
  36. [[get-snapshot-list]]
  37. === Get a list of available snapshots
  38. To view a list of available snapshots in {kib}, go to the main menu and click
  39. *Stack Management > Snapshot and Restore*.
  40. You can also use the <<get-snapshot-repo-api,get repository API>> and the
  41. <<get-snapshot-api,get snapshot API>> to find snapshots that are available to
  42. restore. First, use the get repository API to fetch a list of registered
  43. snapshot repositories.
  44. [source,console]
  45. ----
  46. GET _snapshot
  47. ----
  48. // TEST[setup:setup-snapshots]
  49. Then use the get snapshot API to get a list of snapshots in a specific
  50. repository.
  51. [source,console]
  52. ----
  53. GET _snapshot/my_repository/*?verbose=false
  54. ----
  55. // TEST[setup:setup-snapshots]
  56. [discrete]
  57. [[restore-index-data-stream]]
  58. === Restore an index or data stream
  59. You can restore a snapshot using {kib}'s *Snapshot and Restore* feature or the
  60. <<restore-snapshot-api,restore snapshot API>>.
  61. By default, a restore request attempts to restore all indices and data streams
  62. in a snapshot, including <<system-indices,system indices and system data
  63. streams>>. In most cases, you only need to restore a specific index or data
  64. stream from a snapshot. However, you can't restore an existing open index.
  65. If you're restoring data to a pre-existing cluster, use one of the
  66. following methods to avoid conflicts with existing indices and data streams:
  67. * <<delete-restore>>
  68. * <<rename-on-restore>>
  69. Some {es} features automatically create system indices on cluster startup. To
  70. avoid conflicts with these system indices when restoring data to a new cluster,
  71. see <<restore-exclude-system-indices>>.
  72. [discrete]
  73. [[delete-restore]]
  74. ==== Delete and restore
  75. The simplest way to avoid conflicts is to delete an existing index or data
  76. stream before restoring it. To prevent the accidental re-creation of the index
  77. or data stream, we recommend you temporarily stop all indexing until the restore
  78. operation is complete.
  79. WARNING: If the
  80. <<action-destructive-requires-name,`action.destructive_requires_name`>> cluster
  81. setting is `false`, don't use the <<indices-delete-index,delete index API>> to
  82. target the `*` or `.*` wildcard pattern. If you use {es}'s security features,
  83. this will delete system indices required for authentication. Instead, target the
  84. `*,-.*` wildcard pattern to exclude these system indices and other index names
  85. that begin with a dot (`.`).
  86. [source,console]
  87. ----
  88. # Delete an index
  89. DELETE my-index
  90. # Delete a data stream
  91. DELETE _data_stream/logs-my_app-default
  92. ----
  93. // TEST[setup:setup-snapshots]
  94. In the restore request, explicitly specify any indices and data streams to
  95. restore.
  96. [source,console]
  97. ----
  98. POST _snapshot/my_repository/my_snapshot_2099.05.06/_restore
  99. {
  100. "indices": "my-index,logs-my_app-default"
  101. }
  102. ----
  103. // TEST[continued]
  104. // TEST[s/_restore/_restore?wait_for_completion=true/]
  105. [discrete]
  106. [[rename-on-restore]]
  107. ==== Rename on restore
  108. If you want to avoid deleting existing data, you can instead
  109. rename the indices and data streams you restore. You typically use this method
  110. to compare existing data to historical data from a snapshot. For example, you
  111. can use this method to review documents after an accidental update or deletion.
  112. Before you start, ensure the cluster has enough capacity for both the existing
  113. and restored data.
  114. The following restore snapshot API request prepends `restored-` to the name of
  115. any restored index or data stream.
  116. [source,console]
  117. ----
  118. POST _snapshot/my_repository/my_snapshot_2099.05.06/_restore
  119. {
  120. "indices": "my-index,logs-my_app-default",
  121. "rename_pattern": "(.+)",
  122. "rename_replacement": "restored-$1"
  123. }
  124. ----
  125. // TEST[setup:setup-snapshots]
  126. // TEST[s/_restore/_restore?wait_for_completion=true/]
  127. If the rename options produce two or more indices or data streams with the same
  128. name, the restore operation fails.
  129. If you rename a data stream, its backing indices are also renamed. For example,
  130. if you rename the `logs-my_app-default` data stream to
  131. `restored-logs-my_app-default`, the backing index
  132. `.ds-logs-my_app-default-2099.03.09-000005` is renamed to
  133. `.ds-restored-logs-my_app-default-2099.03.09-000005`.
  134. When the restore operation is complete, you can compare the original and
  135. restored data. If you no longer need an original index or data stream, you can
  136. delete it and use a <<docs-reindex,reindex>> to rename the restored one.
  137. [source,console]
  138. ----
  139. # Delete the original index
  140. DELETE my-index
  141. # Reindex the restored index to rename it
  142. POST _reindex
  143. {
  144. "source": {
  145. "index": "restored-my-index"
  146. },
  147. "dest": {
  148. "index": "my-index"
  149. }
  150. }
  151. # Delete the original data stream
  152. DELETE _data_stream/logs-my_app-default
  153. # Reindex the restored data stream to rename it
  154. POST _reindex
  155. {
  156. "source": {
  157. "index": "restored-logs-my_app-default"
  158. },
  159. "dest": {
  160. "index": "logs-my_app-default",
  161. "op_type": "create"
  162. }
  163. }
  164. ----
  165. // TEST[continued]
  166. [discrete]
  167. [[restore-exclude-system-indices]]
  168. ==== Exclude system indices
  169. Some {es} features, such as the <<geoip-processor,GeoIP processor>>,
  170. automatically create system indices at startup. To avoid naming conflicts with
  171. these indices, use the `-.*` wildcard pattern to exclude system indices and
  172. other dot (`.`) indices from your restore request.
  173. For example, the following request uses the `*,-.*` wildcard pattern to restore
  174. all indices and data streams except dot indices.
  175. [source,console]
  176. ----
  177. POST _snapshot/my_repository/my_snapshot_2099.05.06/_restore
  178. {
  179. "indices": "*,-.*"
  180. }
  181. ----
  182. // TEST[setup:setup-snapshots]
  183. // TEST[s/^/DELETE my-index\nDELETE _data_stream\/logs-my_app-default\n/]
  184. // TEST[s/_restore/_restore?wait_for_completion=true/]
  185. [discrete]
  186. [[restore-feature-state]]
  187. === Restore a feature state
  188. You can restore a feature state to recover system indices, system data streams,
  189. and other configuration data for a feature from a snapshot. Restoring a feature
  190. state is the preferred way to restore system indices and system data streams.
  191. If you restore a snapshot's cluster state, the operation restores all feature
  192. states in the snapshot by default. Similarly, if you don't restore a snapshot's
  193. cluster state, the operation doesn't restore any feature states by default. You
  194. can also choose to restore only specific feature states from a snapshot,
  195. regardless of the cluster state.
  196. To view a snapshot's feature states, use the get snapshot API.
  197. [source,console]
  198. ----
  199. GET _snapshot/my_repository/my_snapshot_2099.05.06
  200. ----
  201. // TEST[setup:setup-snapshots]
  202. The response's `feature_states` property contains a list of features in the
  203. snapshot as well as each feature's indices.
  204. To restore a specific feature state from the snapshot, specify the
  205. `feature_name` from the response in the restore snapshot API's
  206. <<restore-snapshot-api-feature-states,`feature_states`>> parameter. When you
  207. restore a feature state, {es} closes and overwrites the feature's existing
  208. indices.
  209. WARNING: Restoring the `security` feature state overwrites system indices
  210. used for authentication. If you use {ess}, ensure you have access to the {ess}
  211. Console before restoring the `security` feature state. If you run {es} on your
  212. own hardware, <<restore-create-file-realm-user,create a superuser in the file
  213. realm>> to ensure you'll still be able to access your cluster.
  214. To avoid accidentally restoring system indices, system data streams, and other
  215. dot indices, append the `-.*` wildcard pattern to the `indices` value.
  216. [source,console]
  217. ----
  218. POST _snapshot/my_repository/my_snapshot_2099.05.06/_restore
  219. {
  220. "indices": "*,-.*",
  221. "feature_states": [ "geoip" ]
  222. }
  223. ----
  224. // TEST[setup:setup-snapshots]
  225. // TEST[s/^/DELETE my-index\nDELETE _data_stream\/logs-my_app-default\n/]
  226. // TEST[s/_restore/_restore?wait_for_completion=true/]
  227. // TEST[s/",/"/]
  228. // TEST[s/"feature_states": \[ "geoip" \]//]
  229. [discrete]
  230. [[restore-entire-cluster]]
  231. === Restore an entire cluster
  232. In some cases, you need to restore an entire cluster from a snapshot, including
  233. the cluster state and all feature states. These cases should be rare, such as in
  234. the event of a catastrophic failure.
  235. Restoring an entire cluster involves deleting important system indices,
  236. including those used for authentication. Consider whether you can restore
  237. specific indices or data streams instead.
  238. If you're restoring to a different cluster, see <<restore-different-cluster>>
  239. before you start.
  240. . If you <<backup-cluster-configuration,backed up the cluster's configuration
  241. files>>, you can restore them to each node. This step is optional and requires a
  242. <<restart-upgrade,full cluster restart>>.
  243. +
  244. After you shut down a node, copy the backed-up configuration files over to the
  245. node's `$ES_PATH_CONF` directory. Before restarting the node, ensure
  246. `elasticsearch.yml` contains the appropriate node roles, node name, and
  247. other node-specific settings.
  248. +
  249. If you choose to perform this step, you must repeat this process on each node in
  250. the cluster.
  251. . Temporarily stop indexing and turn off the following features:
  252. +
  253. --
  254. * GeoIP database downloader
  255. +
  256. [source,console]
  257. ----
  258. PUT _cluster/settings
  259. {
  260. "persistent": {
  261. "ingest.geoip.downloader.enabled": false
  262. }
  263. }
  264. ----
  265. * ILM
  266. +
  267. [source,console]
  268. ----
  269. POST _ilm/stop
  270. ----
  271. ////
  272. [source,console]
  273. ----
  274. POST _ilm/start
  275. ----
  276. // TEST[continued]
  277. ////
  278. * Machine Learning
  279. +
  280. [source,console]
  281. ----
  282. POST _ml/set_upgrade_mode?enabled=true
  283. ----
  284. ////
  285. [source,console]
  286. ----
  287. POST _ml/set_upgrade_mode?enabled=false
  288. ----
  289. // TEST[continued]
  290. ////
  291. * Monitoring
  292. +
  293. [source,console]
  294. ----
  295. PUT _cluster/settings
  296. {
  297. "persistent": {
  298. "xpack.monitoring.collection.enabled": false
  299. }
  300. }
  301. ----
  302. // TEST[warning:[xpack.monitoring.collection.enabled] setting was deprecated in Elasticsearch and will be removed in a future release! See the breaking changes documentation for the next major version.]
  303. * Watcher
  304. +
  305. [source,console]
  306. ----
  307. POST _watcher/_stop
  308. ----
  309. ////
  310. [source,console]
  311. ----
  312. POST _watcher/_start
  313. ----
  314. // TEST[continued]
  315. ////
  316. --
  317. . {blank}
  318. +
  319. --
  320. [[restore-create-file-realm-user]]
  321. If you use {es} security features, log in to a node host, navigate to the {es}
  322. installation directory, and add a user with the `superuser` role to the file
  323. realm using the <<users-command,`elasticsearch-users`>> tool.
  324. For example, the following command creates a user named `restore_user`.
  325. [source,sh]
  326. ----
  327. ./bin/elasticsearch-users useradd restore_user -p my_password -r superuser
  328. ----
  329. Use this file realm user to authenticate requests until the restore operation is
  330. complete.
  331. --
  332. . Use the <<cluster-update-settings,cluster update settings API>> to set
  333. <<action-destructive-requires-name,`action.destructive_requires_name`>> to
  334. `false`. This lets you delete data streams and indices using wildcards.
  335. +
  336. [source,console]
  337. ----
  338. PUT _cluster/settings
  339. {
  340. "persistent": {
  341. "action.destructive_requires_name": false
  342. }
  343. }
  344. ----
  345. // TEST[setup:setup-snapshots]
  346. . Delete all existing data streams on the cluster.
  347. +
  348. [source,console]
  349. ----
  350. DELETE _data_stream/*?expand_wildcards=all
  351. ----
  352. // TEST[continued]
  353. . Delete all existing indices on the cluster.
  354. +
  355. [source,console]
  356. ----
  357. DELETE *?expand_wildcards=all
  358. ----
  359. // TEST[continued]
  360. . Restore the entire snapshot, including the cluster state. By default,
  361. restoring the cluster state also restores any feature states in the snapshot.
  362. +
  363. [source,console]
  364. ----
  365. POST _snapshot/my_repository/my_snapshot_2099.05.06/_restore
  366. {
  367. "indices": "*",
  368. "include_global_state": true
  369. }
  370. ----
  371. // TEST[continued]
  372. // TEST[s/_restore/_restore?wait_for_completion=true/]
  373. . When the restore operation is complete, resume indexing and restart any
  374. features you stopped:
  375. +
  376. --
  377. * GeoIP database downloader
  378. +
  379. [source,console]
  380. ----
  381. PUT _cluster/settings
  382. {
  383. "persistent": {
  384. "ingest.geoip.downloader.enabled": true
  385. }
  386. }
  387. ----
  388. //TEST[s/true/false/]
  389. * ILM
  390. +
  391. [source,console]
  392. ----
  393. POST _ilm/start
  394. ----
  395. * Machine Learning
  396. +
  397. [source,console]
  398. ----
  399. POST _ml/set_upgrade_mode?enabled=false
  400. ----
  401. * Monitoring
  402. +
  403. [source,console]
  404. ----
  405. PUT _cluster/settings
  406. {
  407. "persistent": {
  408. "xpack.monitoring.collection.enabled": true
  409. }
  410. }
  411. ----
  412. // TEST[warning:[xpack.monitoring.collection.enabled] setting was deprecated in Elasticsearch and will be removed in a future release! See the breaking changes documentation for the next major version.]
  413. // TEST[s/true/false/]
  414. * Watcher
  415. +
  416. [source,console]
  417. ----
  418. POST _watcher/_start
  419. ----
  420. --
  421. . If wanted, reset the `action.destructive_requires_name` cluster setting.
  422. +
  423. [source,console]
  424. ----
  425. PUT _cluster/settings
  426. {
  427. "persistent": {
  428. "action.destructive_requires_name": null
  429. }
  430. }
  431. ----
  432. [discrete]
  433. [[monitor-restore]]
  434. === Monitor a restore
  435. The restore operation uses the <<indices-recovery,shard recovery process>> to
  436. restore an index's primary shards from a snapshot. While the restore operation
  437. recovers primary shards, the cluster will have a `yellow`
  438. <<cluster-health,health status>>.
  439. After all primary shards are recovered, the replication process creates and
  440. distributes replicas across eligible data nodes. When replication is complete,
  441. the cluster health status typically becomes `green`.
  442. You can monitor the cluster health status using the <<cluster-health,cluster
  443. health API>>.
  444. [source,console]
  445. ----
  446. GET _cluster/health
  447. ----
  448. To get detailed information about ongoing shard recoveries, use the
  449. <<indices-recovery,index recovery API>>.
  450. [source,console]
  451. ----
  452. GET my-index/_recovery
  453. ----
  454. // TEST[setup:setup-snapshots]
  455. To view any unassigned shards, use the <<cat-shards,cat shards API>>.
  456. [source,console]
  457. ----
  458. GET _cat/shards?v=true&h=index,shard,prirep,state,node,unassigned.reason&s=state
  459. ----
  460. Unassigned shards have a `state` of `UNASSIGNED`. The `prirep` value is `p` for
  461. primary shards and `r` for replicas. The `unassigned.reason` describes why the
  462. shard remains unassigned.
  463. To get a more in-depth explanation of an unassigned shard's allocation status,
  464. use the <<cluster-allocation-explain,cluster allocation explanation API>>.
  465. [source,console]
  466. ----
  467. GET _cluster/allocation/explain?filter_path=index,node_allocation_decisions.node_name,node_allocation_decisions.deciders.*
  468. {
  469. "index": "my-index",
  470. "shard": 0,
  471. "primary": false,
  472. "current_node": "my-node"
  473. }
  474. ----
  475. // TEST[s/^/PUT my-index\n/]
  476. // TEST[s/"primary": false,/"primary": false/]
  477. // TEST[s/"current_node": "my-node"//]
  478. [discrete]
  479. [[cancel-restore]]
  480. === Cancel a restore
  481. You can delete an index or data stream to cancel its ongoing restore. This also
  482. deletes any existing data in the cluster for the index or data stream. Deleting
  483. an index or data stream doesn't affect the snapshot or its data.
  484. [source,console]
  485. ----
  486. # Delete an index
  487. DELETE my-index
  488. # Delete a data stream
  489. DELETE _data_stream/logs-my_app-default
  490. ----
  491. // TEST[setup:setup-snapshots]
  492. [discrete]
  493. [[restore-different-cluster]]
  494. === Restore to a different cluster
  495. TIP: {ess} can help you restore snapshots from other deployments. See
  496. {cloud}/ec-restoring-snapshots.html#ec-restore-across-clusters[Restore across
  497. clusters].
  498. Snapshots aren't tied to a particular cluster or a cluster name. You can create
  499. a snapshot in one cluster and restore it in another
  500. <<snapshot-restore-version-compatibility,compatible cluster>>. The topology of
  501. the clusters doesn't need to match.
  502. To restore a snapshot, its repository must be
  503. <<snapshots-register-repository,registered>> and available to the new cluster.
  504. If the original cluster still has write access to the repository, register the
  505. repository in `readonly` mode. This prevents multiple clusters from writing to
  506. the repository at the same time and corrupting the repository's contents.
  507. Before you start a restore operation, ensure the new cluster has enough capacity
  508. for any data streams or indices you want to restore. If the new cluster has a
  509. smaller capacity, you can:
  510. * Add nodes or upgrade your hardware to increase capacity.
  511. * Restore fewer indices and data streams.
  512. * Reduce the <<dynamic-index-number-of-replicas,number of replicas>> for
  513. restored indices.
  514. +
  515. For example, the following restore snapshot API request uses the
  516. `index_settings` option to set `index.number_of_replicas` to `1`.
  517. +
  518. [source,console]
  519. ----
  520. POST _snapshot/my_repository/my_snapshot_2099.05.06/_restore
  521. {
  522. "indices": "my-index,logs-my_app-default",
  523. "index_settings": {
  524. "index.number_of_replicas": 1
  525. }
  526. }
  527. ----
  528. // TEST[setup:setup-snapshots]
  529. // TEST[s/^/DELETE my-index\nDELETE _data_stream\/logs-my_app-default\n/]
  530. // TEST[s/_restore/_restore?wait_for_completion=true/]
  531. If indices or backing indices in the original cluster were assigned to particular nodes using
  532. <<shard-allocation-filtering,shard allocation filtering>>, the same rules will be enforced in the new cluster. If the new cluster does not contain nodes with appropriate attributes that a restored index can be allocated on, the
  533. index will not be successfully restored unless these index allocation settings are changed during the restore operation.
  534. The restore operation also checks that restored persistent settings are compatible with the current cluster to avoid accidentally
  535. restoring incompatible settings. If you need to restore a snapshot with incompatible persistent settings, try restoring it without
  536. the <<restore-snapshot-api-include-global-state,global cluster state>>.
  537. [discrete]
  538. [[troubleshoot-restore]]
  539. === Troubleshoot restore errors
  540. Here's how to resolve common errors returned by restore requests.
  541. [discrete]
  542. ==== Cannot restore index [<index>] because an open index with same name already exists in the cluster
  543. You can't restore an open index that already exists. To resolve this error, try
  544. one of the methods in <<restore-index-data-stream>>.
  545. [discrete]
  546. ==== Cannot restore index [<index>] with [x] shards from a snapshot of index [<snapshot-index>] with [y] shards
  547. You can only restore an existing index if it's closed and the index in the
  548. snapshot has the same number of primary shards. This error indicates the index
  549. in the snapshot has a different number of primary shards.
  550. To resolve this error, try one of the methods in <<restore-index-data-stream>>.