restore-snapshot.asciidoc 15 KB

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