restore-snapshot.asciidoc 18 KB

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