take-snapshot.asciidoc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. [[snapshots-take-snapshot]]
  2. == Create a snapshot
  3. A repository can contain multiple snapshots of the same cluster. Snapshots are identified by unique names within the
  4. cluster.
  5. Use the <<put-snapshot-repo-api,put snapshot repository API>> to register or update a snapshot repository, and then use the <<create-snapshot-api,create snapshot API>> to create a snapshot in a repository.
  6. The following request creates a snapshot with the name `snapshot_1` in the repository `my_backup`:
  7. ////
  8. [source,console]
  9. -----------------------------------
  10. PUT /_snapshot/my_backup
  11. {
  12. "type": "fs",
  13. "settings": {
  14. "location": "my_backup_location"
  15. }
  16. }
  17. -----------------------------------
  18. // TESTSETUP
  19. ////
  20. [source,console]
  21. -----------------------------------
  22. PUT /_snapshot/my_backup/snapshot_1?wait_for_completion=true
  23. -----------------------------------
  24. The `wait_for_completion` parameter specifies whether or not the request should return immediately after snapshot
  25. initialization (default) or wait for snapshot completion. During snapshot initialization, information about all
  26. previous snapshots is loaded into memory, which means that in large repositories it may take several seconds (or
  27. even minutes) for this request to return even if the `wait_for_completion` parameter is set to `false`.
  28. By default, a snapshot backs up all data streams and open indices in the cluster. You can change this behavior by
  29. specifying the list of data streams and indices in the body of the snapshot request:
  30. [source,console]
  31. -----------------------------------
  32. PUT /_snapshot/my_backup/snapshot_2?wait_for_completion=true
  33. {
  34. "indices": "data_stream_1,index_1,index_2",
  35. "ignore_unavailable": true,
  36. "include_global_state": false,
  37. "metadata": {
  38. "taken_by": "kimchy",
  39. "taken_because": "backup before upgrading"
  40. }
  41. }
  42. -----------------------------------
  43. // TEST[skip:cannot complete subsequent snapshot]
  44. Use the `indices` parameter to list the data streams and indices that should be included in the snapshot. This parameter supports
  45. <<multi-index,multi-target syntax>>, although the options that control the behavior of multi-index syntax
  46. must be supplied in the body of the request, rather than as request parameters.
  47. Data stream backups include the stream's backing indices and metadata, such as
  48. the current <<data-streams-generation,generation>> and timestamp field.
  49. You can also choose to include only specific backing indices in a snapshot.
  50. However, these backups do not include the associated data stream's
  51. metadata or its other backing indices.
  52. [discrete]
  53. [[create-snapshot-process-details]]
  54. === Snapshot process details
  55. The snapshot process is incremental. In the process of making the snapshot, {es} analyses
  56. the list of the data stream and index files that are already stored in the repository and copies only files that were created or
  57. changed since the last snapshot. This process allows multiple snapshots to be preserved in the repository in a compact form.
  58. The snapshot process is executed in non-blocking fashion. All indexing and searching operations can continue to run against the data stream or index
  59. that is being snapshotted. However, a snapshot represents a point-in-time view
  60. at the moment when snapshot was created, so no records that were added to the data stream or index after the snapshot process was started
  61. will be included in the snapshot.
  62. The snapshot process starts immediately for the primary shards that have been started and are not relocating at the moment. {es} waits for
  63. relocation or initialization of shards to complete before snapshotting them.
  64. Besides creating a copy of each data stream and index, the snapshot process can also store global cluster metadata, which includes persistent
  65. cluster settings and templates. The transient settings and registered snapshot repositories are not stored as part of
  66. the snapshot.
  67. Only one snapshot process can be started in the cluster at any time. While a
  68. snapshot of a particular shard is being
  69. created, this shard cannot be moved to another node, which can interfere with rebalancing and allocation
  70. filtering. {es} can only move a shard to another node (according to the current allocation
  71. filtering settings and rebalancing algorithm) after the snapshot process
  72. is finished.
  73. After a snapshot is created, use the <<get-snapshot-api,Get snapshot API>> to retrieve information about a snapshot. See <<snapshots-monitor-snapshot-restore,Monitor snapshot and restore progress>> to learn more about retrieving snapshot status.
  74. [discrete]
  75. [[create-snapshot-options]]
  76. === Options for creating a snapshot
  77. The create snapshot request supports the
  78. `ignore_unavailable` option. Setting it to `true` will cause data streams and indices that do not exist to be ignored during snapshot
  79. creation. By default, when the `ignore_unavailable` option is not set and a data stream or index is missing, the snapshot request will fail.
  80. By setting `include_global_state` to `false` it's possible to prevent the cluster global state to be stored as part of
  81. the snapshot.
  82. IMPORTANT: The global cluster state includes the cluster's index
  83. templates, such as those <<create-a-data-stream-template,matching a data
  84. stream>>. If your snapshot includes data streams, we recommend storing the
  85. cluster state as part of the snapshot. This lets you later restored any
  86. templates required for a data stream.
  87. By default, the entire snapshot will fail if one or more indices participating in the snapshot do not have
  88. all primary shards available. You can change this behaviour by setting `partial` to `true`. The `expand_wildcards`
  89. option can be used to control whether hidden and closed indices will be included in the snapshot, and defaults to `all`.
  90. Use the `metadata` field to attach arbitrary metadata to the snapsho,
  91. such as who took the snapshot,
  92. why it was taken, or any other data that might be useful.
  93. Snapshot names can be automatically derived using <<date-math-index-names,date math expressions>>, similarly as when creating
  94. new data streams or indices. Special characters must be URI encoded.
  95. For example, use the <<create-snapshot-api,create snapshot API>> to create
  96. a snapshot with the current day in the name, such as `snapshot-2020.07.11`:
  97. [source,console]
  98. -----------------------------------
  99. PUT /_snapshot/my_backup/<snapshot-{now/d}>
  100. PUT /_snapshot/my_backup/%3Csnapshot-%7Bnow%2Fd%7D%3E
  101. -----------------------------------
  102. // TEST[continued]