register-repository.asciidoc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. [[snapshots-register-repository]]
  2. == Register a snapshot repository
  3. ++++
  4. <titleabbrev>Register a repository</titleabbrev>
  5. ++++
  6. This guide shows you how to register a snapshot repository. A snapshot
  7. repository is an off-cluster storage location for your snapshots. You must
  8. register a repository before you can take or restore snapshots.
  9. In this guide, you’ll learn how to:
  10. * Register a snapshot repository
  11. * Verify that a repository is functional
  12. * Clean up a repository to remove unneeded files
  13. [discrete]
  14. [[snapshot-repo-prereqs]]
  15. === Prerequisites
  16. // tag::kib-snapshot-prereqs[]
  17. * To use {kib}'s **Snapshot and Restore** feature, you must have the following
  18. permissions:
  19. ** <<privileges-list-cluster,Cluster privileges>>: `monitor`, `manage_slm`,
  20. `cluster:admin/snapshot`, and `cluster:admin/repository`
  21. ** <<privileges-list-indices,Index privilege>>: `all` on the `monitor` index
  22. // end::kib-snapshot-prereqs[]
  23. include::apis/put-repo-api.asciidoc[tag=put-repo-api-prereqs]
  24. [discrete]
  25. [[snapshot-repo-considerations]]
  26. === Considerations
  27. When registering a snapshot repository, keep the following in mind:
  28. * Each snapshot repository is separate and independent. {es} doesn't share
  29. data between repositories.
  30. * {blank}
  31. +
  32. --
  33. // tag::multi-cluster-repo[]
  34. If you register the same snapshot repository with multiple clusters, only one
  35. cluster should have write access to the repository. On other clusters, register
  36. the repository as read-only.
  37. This prevents multiple clusters from writing to the repository at the same time
  38. and corrupting the repository’s contents.
  39. // end::multi-cluster-repo[]
  40. --
  41. * Use a different snapshot repository for each major version of {es}. Mixing
  42. snapshots from different major versions can corrupt a repository’s contents.
  43. [discrete]
  44. [[manage-snapshot-repos]]
  45. === Manage snapshot repositories
  46. You can register and manage snapshot repositories in two ways:
  47. * {kib}'s **Snapshot and Restore** feature
  48. * {es}'s <<snapshot-restore-repo-apis,snapshot repository management APIs>>
  49. To manage repositories in {kib}, go to the main menu and click **Stack
  50. Management** > **Snapshot and Restore** > **Repositories**. To register a
  51. snapshot repository, click **Register repository**.
  52. [discrete]
  53. [[snapshot-repo-types]]
  54. === Snapshot repository types
  55. Supported snapshot repository types vary based on your deployment type.
  56. [discrete]
  57. [[ess-repo-types]]
  58. ==== {ess} repository types
  59. {ess-trial}[{ess} deployments] automatically register the
  60. {cloud}/ec-snapshot-restore.html[`found-snapshots`] repository. {ess} uses this
  61. repository and the `cloud-snapshot-policy` to take periodic snapshots of your
  62. cluster. You can also use the `found-snapshots` repository for your own
  63. <<automate-snapshots-slm,{slm-init} policies>> or to store searchable snapshots.
  64. The `found-snapshots` repository is specific to each deployment. However, you
  65. can restore snapshots from another deployment's `found-snapshots` repository if
  66. the deployments are under the same account and in the same region. See
  67. {cloud}/ec_share_a_repository_across_clusters.html[Share a repository across
  68. clusters].
  69. {ess} deployments also support the following repository types:
  70. * {cloud}/ec-aws-custom-repository.html[AWS S3]
  71. * {cloud}/ec-gcs-snapshotting.html[Google Cloud Storage (GCS)]
  72. * {cloud}/ec-azure-snapshotting.html[Microsoft Azure]
  73. * <<snapshots-source-only-repository>>
  74. [discrete]
  75. [[self-managed-repo-types]]
  76. ==== Self-managed repository types
  77. If you run the {es} on your own hardware, you can use the following built-in
  78. snapshot repository types:
  79. * <<snapshots-filesystem-repository,Shared file system>>
  80. * <<snapshots-read-only-repository>>
  81. * <<snapshots-source-only-repository>>
  82. [[snapshots-repository-plugins]]
  83. Other repository types are available through official plugins:
  84. * {plugins}/repository-s3.html[AWS S3]
  85. * {plugins}/repository-gcs.html[Google Cloud Storage (GCS)]
  86. * {plugins}/repository-hdfs.html[Hadoop Distributed File System (HDFS)]
  87. * {plugins}/repository-azure.html[Microsoft Azure]
  88. You can also use alternative implementations of these repository types, such as
  89. MinIO, as long as they're compatible. To verify a repository's compatibility,
  90. see <<snapshots-repository-verification>>.
  91. [discrete]
  92. [[snapshots-filesystem-repository]]
  93. ==== Shared file system repository
  94. // tag::on-prem-repo-type[]
  95. NOTE: This repository type is only available if you run {es} on your own
  96. hardware. If you use {ess}, see <<ess-repo-types>>.
  97. // end::on-prem-repo-type[]
  98. Use a shared file system repository to store snapshots on a
  99. shared file system.
  100. To register a shared file system repository, first mount the file system to the
  101. same location on all master and data nodes. Then add the file system's
  102. path or parent directory to the `path.repo` setting in `elasticsearch.yml` for
  103. each master and data node. For running clusters, this requires a
  104. <<restart-cluster-rolling,rolling restart>> of each node.
  105. IMPORTANT: By default, a network file system (NFS) uses user IDs (UIDs) and
  106. group IDs (GIDs) to match accounts across nodes. If your shared file system is
  107. an NFS and your nodes don't use the same UIDs and GIDs, update your NFS
  108. configuration to account for this.
  109. Supported `path.repo` values vary by platform:
  110. include::{es-repo-dir}/tab-widgets/register-fs-repo-widget.asciidoc[]
  111. [discrete]
  112. [[snapshots-read-only-repository]]
  113. ==== Read-only URL repository
  114. include::register-repository.asciidoc[tag=on-prem-repo-type]
  115. You can use a URL repository to give a cluster read-only access to a shared file
  116. system. Since URL repositories are always read-only, they're a safer and more
  117. convenient alternative to registering a read-only shared filesystem repository.
  118. Use {kib} or the <<put-snapshot-repo-api,create snapshot repository API>> to
  119. register a URL repository.
  120. [source,console]
  121. ----
  122. PUT _snapshot/my_read_only_url_repository
  123. {
  124. "type": "url",
  125. "settings": {
  126. "url": "file:/mount/backups/my_fs_backup_location"
  127. }
  128. }
  129. ----
  130. // TEST[skip:no access to url file path]
  131. [discrete]
  132. [[snapshots-source-only-repository]]
  133. ==== Source-only repository
  134. You can use a source-only repository to take minimal, source-only snapshots that
  135. use up to 50% less disk space than regular snapshots.
  136. Unlike other repository types, a source-only repository doesn't directly store
  137. snapshots. It delegates storage to another registered snapshot repository.
  138. When you take a snapshot using a source-only repository, {es} creates a
  139. source-only snapshot in the delegated storage repository. This snapshot only
  140. contains stored fields and metadata. It doesn't include index or doc values
  141. structures and isn't immediately searchable when restored. To search the
  142. restored data, you first have to <<docs-reindex,reindex>> it into a new data
  143. stream or index.
  144. [IMPORTANT]
  145. ==================================================
  146. Source-only snapshots are only supported if the `_source` field is enabled and no source-filtering is applied.
  147. When you restore a source-only snapshot:
  148. * The restored index is read-only and can only serve `match_all` search or scroll requests to enable reindexing.
  149. * Queries other than `match_all` and `_get` requests are not supported.
  150. * The mapping of the restored index is empty, but the original mapping is available from the types top
  151. level `meta` element.
  152. ==================================================
  153. Before registering a source-only repository, use {kib} or the
  154. <<put-snapshot-repo-api,create snapshot repository API>> to register a snapshot
  155. repository of another type to use for storage. Then register the source-only
  156. repository and specify the delegated storage repository in the request.
  157. [source,console]
  158. ----
  159. PUT _snapshot/my_src_only_repository
  160. {
  161. "type": "source",
  162. "settings": {
  163. "delegate_type": "fs",
  164. "location": "my_backup_location"
  165. }
  166. }
  167. ----
  168. // TEST[continued]
  169. [discrete]
  170. [[snapshots-repository-verification]]
  171. === Verify a repository
  172. When you register a snapshot repository, {es} automatically verifies that the
  173. repository is available and functional on all master and data nodes.
  174. To disable this verification, set the <<put-snapshot-repo-api,create snapshot
  175. repository API>>'s `verify` query parameter to `false`. You can't disable
  176. repository verification in {kib}.
  177. [source,console]
  178. ----
  179. PUT _snapshot/my_unverified_backup?verify=false
  180. {
  181. "type": "fs",
  182. "settings": {
  183. "location": "my_unverified_backup_location"
  184. }
  185. }
  186. ----
  187. // TEST[continued]
  188. If wanted, you can manually run the repository verification check. To verify a
  189. repository in {kib}, go to the **Repositories** list page and click the name of
  190. a repository. Then click **Verify repository**. You can also use the
  191. <<verify-snapshot-repo-api,verify snapshot repository API>>.
  192. [source,console]
  193. ----
  194. POST _snapshot/my_unverified_backup/_verify
  195. ----
  196. // TEST[continued]
  197. If successful, the request returns a list of nodes used to verify the
  198. repository. If verification fails, the request returns an error.
  199. You can test a repository more thoroughly using the
  200. <<repo-analysis-api,repository analysis API>>.
  201. [discrete]
  202. [[snapshots-repository-cleanup]]
  203. === Clean up a repository
  204. Repositories can over time accumulate data that is not referenced by any existing snapshot. This is a result of the data safety guarantees
  205. the snapshot functionality provides in failure scenarios during snapshot creation and the decentralized nature of the snapshot creation
  206. process. This unreferenced data does in no way negatively impact the performance or safety of a snapshot repository but leads to higher
  207. than necessary storage use. To remove this unreferenced data, you can run a cleanup operation on the repository. This will
  208. trigger a complete accounting of the repository's contents and delete any unreferenced data.
  209. To run the repository cleanup operation in {kib}, go to the **Repositories**
  210. list page and click the name of a repository. Then click **Clean up
  211. repository**.
  212. You can also use the <<clean-up-snapshot-repo-api,clean up snapshot repository
  213. API>>.
  214. [source,console]
  215. ----
  216. POST _snapshot/my_repository/_cleanup
  217. ----
  218. // TEST[continued]
  219. The API returns:
  220. [source,console-result]
  221. ----
  222. {
  223. "results": {
  224. "deleted_bytes": 20,
  225. "deleted_blobs": 5
  226. }
  227. }
  228. ----
  229. Depending on the concrete repository implementation the numbers shown for bytes free as well as the number of blobs removed will either
  230. be an approximation or an exact result. Any non-zero value for the number of blobs removed implies that unreferenced blobs were found and
  231. subsequently cleaned up.
  232. Please note that most of the cleanup operations executed by this endpoint are automatically executed when deleting any snapshot from a
  233. repository. If you regularly delete snapshots, you will in most cases not get any or only minor space savings from using this functionality
  234. and should lower your frequency of invoking it accordingly.
  235. [discrete]
  236. [[snapshots-repository-backup]]
  237. === Back up a repository
  238. You may wish to make an independent backup of your repository, for instance so
  239. that you have an archive copy of its contents that you can use to recreate the
  240. repository in its current state at a later date.
  241. You must ensure that {es} does not write to the repository while you are taking
  242. the backup of its contents. You can do this by unregistering it, or registering
  243. it with `readonly: true`, on all your clusters. If {es} writes any data to the
  244. repository during the backup then the contents of the backup may not be
  245. consistent and it may not be possible to recover any data from it in future.
  246. Alternatively, if your repository supports it, you may take an atomic snapshot
  247. of the underlying filesystem and then take a backup of this filesystem
  248. snapshot. It is very important that the filesystem snapshot is taken
  249. atomically.
  250. WARNING: You cannot use filesystem snapshots of individual nodes as a backup
  251. mechanism. You must use the {es} snapshot and restore feature to copy the
  252. cluster contents to a separate repository. Then, if desired, you can take a
  253. filesystem snapshot of this repository.
  254. When restoring a repository from a backup, you must not register the repository
  255. with {es} until the repository contents are fully restored. If you alter the
  256. contents of a repository while it is registered with {es} then the repository
  257. may become unreadable or may silently lose some of its contents.