take-snapshot.asciidoc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. [[snapshots-take-snapshot]]
  2. == Create a snapshot
  3. ////
  4. [source,console]
  5. ----
  6. PUT _slm/policy/nightly-snapshots
  7. {
  8. "schedule": "0 30 1 * * ?",
  9. "name": "<nightly-snap-{now/d}>",
  10. "repository": "my_repository",
  11. "config": {
  12. "indices": "*",
  13. "include_global_state": true
  14. },
  15. "retention": {
  16. "expire_after": "30d",
  17. "min_count": 5,
  18. "max_count": 50
  19. }
  20. }
  21. ----
  22. // TEST[setup:setup-repository]
  23. // TESTSETUP
  24. ////
  25. This guide shows you how to take snapshots of a running cluster. You can later
  26. <<snapshots-restore-snapshot,restore a snapshot>> to recover or transfer its
  27. data.
  28. In this guide, you’ll learn how to:
  29. * Automate snapshot creation and retention with {slm} ({slm-init})
  30. * Manually take a snapshot
  31. * Monitor a snapshot's progress
  32. * Delete or cancel a snapshot
  33. * Back up cluster configuration files
  34. The guide also provides tips for creating dedicated cluster state snapshots and
  35. taking snapshots at different time intervals.
  36. [discrete]
  37. [[create-snapshot-prereqs]]
  38. === Prerequisites
  39. include::register-repository.asciidoc[tag=kib-snapshot-prereqs]
  40. * You can only take a snapshot from a running cluster with an elected
  41. <<master-node,master node>>.
  42. * A snapshot repository must be <<snapshots-register-repository,registered>> and
  43. available to the cluster.
  44. * The cluster's global metadata must be readable. To include an index in a
  45. snapshot, the index and its metadata must also be readable. Ensure there aren't
  46. any <<cluster-read-only,cluster blocks>> or <<index-modules-blocks,index
  47. blocks>> that prevent read access.
  48. [discrete]
  49. [[create-snapshot-considerations]]
  50. === Considerations
  51. * Each snapshot must have a unique name within its repository. Attempts to
  52. create a snapshot with the same name as an existing snapshot will fail.
  53. * Snapshots are automatically deduplicated. You can take frequent snapshots with
  54. little impact to your storage overhead.
  55. * Each snapshot is logically independent. You can delete a snapshot without
  56. affecting other snapshots.
  57. * Taking a snapshot can temporarily pause shard allocations.
  58. See <<snapshots-shard-allocation>>.
  59. * Taking a snapshot doesn't block indexing or other requests. However, the
  60. snapshot won't include changes made after the snapshot process starts.
  61. * You can take multiple snapshots at the same time. The
  62. <<snapshot-max-concurrent-ops,`snapshot.max_concurrent_operations`>> cluster
  63. setting limits the maximum number of concurrent snapshot operations.
  64. * If you include a data stream in a snapshot, the snapshot also includes the
  65. stream’s backing indices and metadata.
  66. +
  67. You can also include only specific backing indices in a snapshot. However, the
  68. snapshot won't include the data stream’s metadata or its other backing indices.
  69. * A snapshot can include a data stream but exclude specific backing indices.
  70. When you restore such a data stream, it will contain only backing indices in the
  71. snapshot. If the stream’s original write index is not in the snapshot, the most
  72. recent backing index from the snapshot becomes the stream’s write index.
  73. [discrete]
  74. [[automate-snapshots-slm]]
  75. === Automate snapshots with {slm-init}
  76. {slm-cap} ({slm-init}) is the easiest way to regularly back up a cluster. An
  77. {slm-init} policy automatically takes snapshots on a preset schedule. The policy
  78. can also delete snapshots based on retention rules you define.
  79. TIP: {ess} deployments automatically include the `cloud-snapshot-policy`
  80. {slm-init} policy. {ess} uses this policy to take periodic snapshots of your
  81. cluster. For more information, see the {cloud}/ec-snapshot-restore.html[{ess}
  82. snapshot documentation].
  83. [discrete]
  84. [[slm-security]]
  85. ==== {slm-init} security
  86. The following <<privileges-list-cluster,cluster privileges>> control access to
  87. the {slm-init} actions when {es} {security-features} are enabled:
  88. `manage_slm`::
  89. Allows a user to perform all {slm-init} actions, including
  90. creating and updating policies and starting and stopping {slm-init}.
  91. `read_slm`::
  92. Allows a user to perform all read-only {slm-init} actions, such as getting
  93. policies and checking the {slm-init} status.
  94. `cluster:admin/snapshot/*`::
  95. Allows a user to take and delete snapshots of any index, whether or not they
  96. have access to that index.
  97. You can create and manage roles to assign these privileges through {kib}
  98. Management.
  99. To grant the privileges necessary to create and manage {slm-init} policies and
  100. snapshots, you can set up a role with the `manage_slm` and
  101. `cluster:admin/snapshot/*` cluster privileges and full access to the {slm-init}
  102. history indices.
  103. For example, the following request creates an `slm-admin` role:
  104. [source,console]
  105. ----
  106. POST _security/role/slm-admin
  107. {
  108. "cluster": [ "manage_slm", "cluster:admin/snapshot/*" ],
  109. "indices": [
  110. {
  111. "names": [ ".slm-history-*" ],
  112. "privileges": [ "all" ]
  113. }
  114. ]
  115. }
  116. ----
  117. // TEST[skip:security is not enabled here]
  118. To grant read-only access to {slm-init} policies and the snapshot history,
  119. you can set up a role with the `read_slm` cluster privilege and read access
  120. to the {slm} history indices.
  121. For example, the following request creates a `slm-read-only` role:
  122. [source,console]
  123. ----
  124. POST _security/role/slm-read-only
  125. {
  126. "cluster": [ "read_slm" ],
  127. "indices": [
  128. {
  129. "names": [ ".slm-history-*" ],
  130. "privileges": [ "read" ]
  131. }
  132. ]
  133. }
  134. ----
  135. // TEST[skip:security is not enabled here]
  136. [discrete]
  137. [[create-slm-policy]]
  138. ==== Create an {slm-init} policy
  139. To manage {slm-init} in {kib}, go to the main menu and click **Stack
  140. Management** > **Snapshot and Restore** > **Policies**. To create a policy,
  141. click **Create policy**.
  142. You can also manage {slm-init} using the
  143. <<snapshot-lifecycle-management-api,{slm-init} APIs>>. To create a policy, use
  144. the <<slm-api-put-policy,create {slm-init} policy API>>.
  145. The following request creates a policy that backs up the cluster state, all data
  146. streams, and all indices daily at 1:30 a.m. UTC.
  147. [source,console]
  148. ----
  149. PUT _slm/policy/nightly-snapshots
  150. {
  151. "schedule": "0 30 1 * * ?", <1>
  152. "name": "<nightly-snap-{now/d}>", <2>
  153. "repository": "my_repository", <3>
  154. "config": {
  155. "indices": "*", <4>
  156. "include_global_state": true <5>
  157. },
  158. "retention": { <6>
  159. "expire_after": "30d",
  160. "min_count": 5,
  161. "max_count": 50
  162. }
  163. }
  164. ----
  165. <1> When to take snapshots, written in <<schedule-cron,Cron syntax>>.
  166. <2> Snapshot name. Supports <<api-date-math-index-names,date math>>. To prevent
  167. naming conflicts, the policy also appends a UUID to each snapshot name.
  168. <3> <<snapshots-register-repository,Registered snapshot repository>> used to
  169. store the policy's snapshots.
  170. <4> Data streams and indices to include in the policy's snapshots.
  171. <5> If `true`, the policy's snapshots include the cluster state. This also
  172. includes all feature states by default. To only include specific feature
  173. states, see <<back-up-specific-feature-state>>.
  174. <6> Optional retention rules. This configuration keeps snapshots for 30 days,
  175. retaining at least 5 and no more than 50 snapshots regardless of age. See
  176. <<slm-retention-task>> and <<snapshot-retention-limits>>.
  177. [discrete]
  178. [[manually-run-slm-policy]]
  179. ==== Manually run an {slm-init} policy
  180. You can manually run an {slm-init} policy to immediately create a snapshot. This
  181. is useful for testing a new policy or taking a snapshot before an upgrade.
  182. Manually running a policy doesn't affect its snapshot schedule.
  183. To run a policy in {kib}, go to the **Policies** page and click the run icon
  184. under the **Actions** column. You can also use the
  185. <<slm-api-execute-lifecycle,execute {slm-init} policy API>>.
  186. [source,console]
  187. ----
  188. POST _slm/policy/nightly-snapshots/_execute
  189. ----
  190. // TEST[skip:we can't easily handle snapshots from docs tests]
  191. The snapshot process runs in the background. To monitor its progress, see
  192. <<monitor-snapshot>>.
  193. [discrete]
  194. [[slm-retention-task]]
  195. ==== {slm-init} retention
  196. {slm-init} snapshot retention is a cluster-level task that runs separately from
  197. a policy's snapshot schedule. To control when the {slm-init} retention task
  198. runs, configure the <<slm-retention-schedule,`slm.retention_schedule`>> cluster
  199. setting.
  200. [source,console]
  201. ----
  202. PUT _cluster/settings
  203. {
  204. "persistent" : {
  205. "slm.retention_schedule" : "0 30 1 * * ?"
  206. }
  207. }
  208. ----
  209. To immediately run the retention task, use the
  210. <<slm-api-execute-retention,execute {slm-init} retention policy API>>.
  211. [source,console]
  212. ----
  213. POST _slm/_execute_retention
  214. ----
  215. An {slm-init} policy's retention rules only apply to snapshots created using the
  216. policy. Other snapshots don't count toward the policy's retention limits.
  217. [discrete]
  218. [[snapshot-retention-limits]]
  219. ==== Snapshot retention limits
  220. We recommend you include retention rules in your {slm-init} policy to delete
  221. snapshots you no longer need.
  222. A snapshot repository can safely scale to thousands of snapshots. However, to
  223. manage its metadata, a large repository requires more memory on the master node.
  224. Retention rules ensure a repository's metadata doesn't grow to a size that could
  225. destabilize the master node.
  226. [discrete]
  227. [[manually-create-snapshot]]
  228. === Manually create a snapshot
  229. To take a snapshot without an {slm-init} policy, use the
  230. <<create-snapshot-api,create snapshot API>>. The snapshot name supports
  231. <<api-date-math-index-names,date math>>.
  232. [source,console]
  233. ----
  234. # PUT _snapshot/my_repository/<my_snapshot_{now/d}>
  235. PUT _snapshot/my_repository/%3Cmy_snapshot_%7Bnow%2Fd%7D%3E
  236. ----
  237. // TEST[s/3E/3E?wait_for_completion=true/]
  238. Depending on its size, a snapshot can take a while to complete. By default,
  239. the create snapshot API only initiates the snapshot process, which runs in the
  240. background. To block the client until the snapshot finishes, set the
  241. `wait_for_completion` query parameter to `true`.
  242. [source,console]
  243. ----
  244. PUT _snapshot/my_repository/my_snapshot?wait_for_completion=true
  245. ----
  246. You can also clone an existing snapshot using <<clone-snapshot-api,clone
  247. snapshot API>>.
  248. [discrete]
  249. [[monitor-snapshot]]
  250. === Monitor a snapshot
  251. To monitor any currently running snapshots, use the <<get-snapshot-api,get
  252. snapshot API>> with the `_current` request path parameter.
  253. [source,console]
  254. ----
  255. GET _snapshot/my_repository/_current
  256. ----
  257. To get a complete breakdown of each shard participating in any currently running
  258. snapshots, use the <<get-snapshot-api,get snapshot status API>>.
  259. [source,console]
  260. ----
  261. GET _snapshot/_status
  262. ----
  263. [discrete]
  264. [[check-slm-history]]
  265. ==== Check {slm-init} history
  266. To get more information about a cluster's {slm-init} execution history,
  267. including stats for each {slm-init} policy, use the <<slm-api-get-stats,get
  268. {slm-init} stats API>>. The API also returns information about the cluster's
  269. snapshot retention task history.
  270. [source,console]
  271. ----
  272. GET _slm/stats
  273. ----
  274. To get information about a specific {slm-init} policy's execution history, use
  275. the <<slm-api-get-policy,get {slm-init} policy API>>. The response includes:
  276. * The next scheduled policy execution.
  277. * The last time the policy successfully started the snapshot process, if
  278. applicable. A successful start doesn't guarantee the snapshot completed.
  279. * The last time policy execution failed, if applicable, and the associated
  280. error.
  281. [source,console]
  282. ----
  283. GET _slm/policy/nightly-snapshots
  284. ----
  285. [discrete]
  286. [[delete-snapshot]]
  287. === Delete or cancel a snapshot
  288. To delete a snapshot in {kib}, go to the **Snapshots** page and click the trash
  289. icon under the **Actions** column. You can also use the
  290. <<delete-snapshot-api,delete snapshot API>>.
  291. [source,console]
  292. ----
  293. DELETE _snapshot/my_repository/my_snapshot_2099.05.06
  294. ----
  295. // TEST[setup:setup-snapshots]
  296. If you delete a snapshot that's in progress, {es} cancels it. The snapshot
  297. process halts and deletes any files created for the snapshot. Deleting a
  298. snapshot doesn't delete files used by other snapshots.
  299. [discrete]
  300. [[back-up-config-files]]
  301. === Back up configuration files
  302. If you run {es} on your own hardware, we recommend that, in addition to backups,
  303. you take regular backups of the files in each node's
  304. <<config-files-location,`$ES_PATH_CONF` directory>> using the file backup software
  305. of your choice. Snapshots don't back up these files. Also note that these files will
  306. differ on each node, so each node's files should be backed up individually.
  307. IMPORTANT: The `elasticsearch.keystore`, TLS keys, and <<ref-saml-settings, SAML>>,
  308. <<ref-oidc-settings, OIDC>>, and <<ref-kerberos-settings, Kerberos>>
  309. realms private key files contain sensitive information. Consider encrypting
  310. your backups of these files.
  311. [discrete]
  312. [[back-up-specific-feature-state]]
  313. === Back up a specific feature state
  314. By default, a snapshot that includes the cluster state also includes all
  315. <<feature-state,feature states>>. Similarly, a snapshot that excludes the
  316. cluster state excludes all feature states by default.
  317. You can also configure a snapshot to only include specific feature states,
  318. regardless of the cluster state.
  319. To get a list of available features, use the <<get-features-api,get features
  320. API>>.
  321. [source,console]
  322. ----
  323. GET _features
  324. ----
  325. The API returns:
  326. [source,console-result]
  327. ----
  328. {
  329. "features": [
  330. {
  331. "name": "tasks",
  332. "description": "Manages task results"
  333. },
  334. {
  335. "name": "kibana",
  336. "description": "Manages Kibana configuration and reports"
  337. },
  338. {
  339. "name": "security",
  340. "description": "Manages configuration for Security features, such as users and roles"
  341. },
  342. ...
  343. ]
  344. }
  345. ----
  346. // TESTRESPONSE[skip:response may vary based on features in test cluster]
  347. To include a specific feature state in a snapshot, specify the feature `name` in
  348. the `feature_states` array.
  349. For example, the following {slm-init} policy only includes feature states for
  350. the {kib} and {es} security features in its snapshots.
  351. [source,console]
  352. ----
  353. PUT _slm/policy/nightly-snapshots
  354. {
  355. "schedule": "0 30 2 * * ?",
  356. "name": "<nightly-snap-{now/d}>",
  357. "repository": "my_repository",
  358. "config": {
  359. "indices": "*",
  360. "include_global_state": true,
  361. "feature_states": [
  362. "kibana",
  363. "security"
  364. ]
  365. },
  366. "retention": {
  367. "expire_after": "30d",
  368. "min_count": 5,
  369. "max_count": 50
  370. }
  371. }
  372. ----
  373. Any index or data stream that's part of the feature state will display in a
  374. snapshot's contents. For example, if you back up the `security` feature state,
  375. the `security-*` system indices display in the <<get-snapshot-api,get snapshot
  376. API>>'s response under both `indices` and `feature_states`.
  377. [discrete]
  378. [[cluster-state-snapshots]]
  379. === Dedicated cluster state snapshots
  380. Some feature states contain sensitive data. For example, the `security` feature
  381. state includes system indices that may contain user names and encrypted password
  382. hashes. Because passwords are stored using <<hashing-settings, cryptographic hashes>>,
  383. the disclosure of a snapshot would not automatically enable a third party to
  384. authenticate as one of your users or use API keys. However, it would disclose
  385. confidential information, and if a third party can modify snapshots, they could
  386. install a back door.
  387. To better protect this data, consider creating a dedicated repository and
  388. {slm-init} policy for snapshots of the cluster state. This lets you strictly
  389. limit and audit access to the repository.
  390. For example, the following {slm-init} policy only backs up the cluster state.
  391. The policy stores these snapshots in a dedicated repository.
  392. [source,console]
  393. ----
  394. PUT _slm/policy/nightly-cluster-state-snapshots
  395. {
  396. "schedule": "0 30 2 * * ?",
  397. "name": "<nightly-cluster-state-snap-{now/d}>",
  398. "repository": "my_secure_repository",
  399. "config": {
  400. "include_global_state": true, <1>
  401. "indices": "-*" <2>
  402. },
  403. "retention": {
  404. "expire_after": "30d",
  405. "min_count": 5,
  406. "max_count": 50
  407. }
  408. }
  409. ----
  410. // TEST[s/my_secure_repository/my_repository/]
  411. <1> Includes the cluster state. This also includes all feature states by
  412. default.
  413. <2> Excludes regular data streams and indices.
  414. If you take dedicated snapshots of the cluster state, you'll need to exclude the
  415. cluster state from your other snapshots. For example:
  416. [source,console]
  417. ----
  418. PUT _slm/policy/nightly-snapshots
  419. {
  420. "schedule": "0 30 2 * * ?",
  421. "name": "<nightly-snap-{now/d}>",
  422. "repository": "my_repository",
  423. "config": {
  424. "include_global_state": false, <1>
  425. "indices": "*" <2>
  426. },
  427. "retention": {
  428. "expire_after": "30d",
  429. "min_count": 5,
  430. "max_count": 50
  431. }
  432. }
  433. ----
  434. <1> Excludes the cluster state. This also excludes all feature states by
  435. default.
  436. <2> Includes all regular data streams and indices.
  437. [discrete]
  438. [[create-snapshots-different-time-intervals]]
  439. === Create snapshots at different time intervals
  440. If you only use a single {slm-init} policy, it can be difficult to take frequent
  441. snapshots and retain snapshots with longer time intervals.
  442. For example, a policy that takes snapshots every 30 minutes with a maximum of
  443. 100 snapshots will only keep snapshots for approximately two days. While this
  444. setup is great for backing up recent changes, it doesn't let you restore data
  445. from a previous week or month.
  446. To fix this, you can create multiple {slm-init} policies with the same snapshot
  447. repository that run on different schedules. Since a policy's retention rules
  448. only apply to its snapshots, a policy won't delete a snapshot created by another
  449. policy.
  450. For example, the following {slm-init} policy takes hourly snapshots with a
  451. maximum of 24 snapshots. The policy keeps its snapshots for one day.
  452. [source,console]
  453. ----
  454. PUT _slm/policy/hourly-snapshots
  455. {
  456. "name": "<hourly-snapshot-{now/d}>",
  457. "schedule": "0 0 * * * ?",
  458. "repository": "my_repository",
  459. "config": {
  460. "indices": "*",
  461. "include_global_state": true
  462. },
  463. "retention": {
  464. "expire_after": "1d",
  465. "min_count": 1,
  466. "max_count": 24
  467. }
  468. }
  469. ----
  470. The following policy takes nightly snapshots in the same snapshot repository.
  471. The policy keeps its snapshots for one month.
  472. [source,console]
  473. ----
  474. PUT _slm/policy/daily-snapshots
  475. {
  476. "name": "<daily-snapshot-{now/d}>",
  477. "schedule": "0 45 23 * * ?", <1>
  478. "repository": "my_repository",
  479. "config": {
  480. "indices": "*",
  481. "include_global_state": true
  482. },
  483. "retention": {
  484. "expire_after": "30d",
  485. "min_count": 1,
  486. "max_count": 31
  487. }
  488. }
  489. ----
  490. <1> Runs at 11:45 p.m. UTC every day.
  491. The following policy creates monthly snapshots in the same repository. The
  492. policy keeps its snapshots for one year.
  493. [source,console]
  494. ----
  495. PUT _slm/policy/monthly-snapshots
  496. {
  497. "name": "<monthly-snapshot-{now/d}>",
  498. "schedule": "0 56 23 1 * ?", <1>
  499. "repository": "my_repository",
  500. "config": {
  501. "indices": "*",
  502. "include_global_state": true
  503. },
  504. "retention": {
  505. "expire_after": "366d",
  506. "min_count": 1,
  507. "max_count": 12
  508. }
  509. }
  510. ----
  511. <1> Runs on the first of the month at 11:56 p.m. UTC.