restore-snapshot.asciidoc 19 KB

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