register-repository.asciidoc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. [[snapshots-register-repository]]
  2. == Register a snapshot repository
  3. ++++
  4. <titleabbrev>Register repository</titleabbrev>
  5. ++++
  6. [[snapshots-register-repository-description]]
  7. // tag::snapshots-register-repository-tag[]
  8. You must register a snapshot repository before you can perform snapshot and
  9. restore operations. Use the <<put-snapshot-repo-api,put snapshot repository API>> to register or update a snapshot repository. We recommend creating a new snapshot repository for each
  10. major version. The valid repository settings depend on the repository type.
  11. If you register the same snapshot repository with multiple clusters, only
  12. one cluster should have write access to the repository. All other clusters
  13. connected to that repository should set the repository to `readonly` mode.
  14. // end::snapshots-register-repository-tag[]
  15. [IMPORTANT]
  16. ====
  17. The snapshot format can change across major versions, so if you have
  18. clusters on different versions trying to write to the same repository, snapshots
  19. written by one version may not be visible to the other and the repository could
  20. be corrupted. While setting the repository to `readonly` on all but one of the
  21. clusters should work with multiple clusters differing by one major version, it
  22. is not a supported configuration.
  23. ====
  24. [source,console]
  25. -----------------------------------
  26. PUT /_snapshot/my_backup
  27. {
  28. "type": "fs",
  29. "settings": {
  30. "location": "my_backup_location"
  31. }
  32. }
  33. -----------------------------------
  34. // TESTSETUP
  35. Use the <<get-snapshot-api,get snapshot API>> to retrieve information about a registered repository:
  36. [source,console]
  37. -----------------------------------
  38. GET /_snapshot/my_backup
  39. -----------------------------------
  40. This request returns the following response:
  41. [source,console-result]
  42. -----------------------------------
  43. {
  44. "my_backup": {
  45. "type": "fs",
  46. "uuid": "0JLknrXbSUiVPuLakHjBrQ",
  47. "settings": {
  48. "location": "my_backup_location"
  49. }
  50. }
  51. }
  52. -----------------------------------
  53. // TESTRESPONSE[s/"uuid": "0JLknrXbSUiVPuLakHjBrQ"/"uuid": $body.my_backup.uuid/]
  54. To retrieve information about multiple repositories, specify a comma-delimited
  55. list of repositories. You can also use a wildcard (`*`) when
  56. specifying repository names. For example, the following request retrieves
  57. information about all of the snapshot repositories that start with `repo` or
  58. contain `backup`:
  59. [source,console]
  60. -----------------------------------
  61. GET /_snapshot/repo*,*backup*
  62. -----------------------------------
  63. To retrieve information about all registered snapshot repositories, omit the
  64. repository name:
  65. [source,console]
  66. -----------------------------------
  67. GET /_snapshot
  68. -----------------------------------
  69. Alternatively, you can specify `_all`:
  70. [source,console]
  71. -----------------------------------
  72. GET /_snapshot/_all
  73. -----------------------------------
  74. You can unregister a repository using the
  75. <<delete-snapshot-repo-api,delete snapshot repository API>>:
  76. [source,console]
  77. -----------------------------------
  78. DELETE /_snapshot/my_backup
  79. -----------------------------------
  80. When a repository is unregistered, {es} only removes the reference to the
  81. location where the repository is storing the snapshots. The snapshots themselves
  82. are left untouched and in place.
  83. [discrete]
  84. [[snapshots-filesystem-repository]]
  85. === Shared file system repository
  86. Use a shared file system repository (`"type": "fs"`) to store snapshots on a
  87. shared file system.
  88. To register a shared file system repository, first mount the file system to the
  89. same location on all master and data nodes. Then add the file system's
  90. path or parent directory to the `path.repo` setting in `elasticsearch.yml` for
  91. each master and data node. For running clusters, this requires a
  92. <<restart-cluster-rolling,rolling restart>> of each node.
  93. IMPORTANT: By default, a network file system (NFS) uses user IDs (UIDs) and
  94. group IDs (GIDs) to match accounts across nodes. If your shared file system is
  95. an NFS and your nodes don't use the same UIDs and GIDs, update your NFS
  96. configuration to account for this.
  97. Supported `path.repo` values vary by platform:
  98. include::{es-repo-dir}/tab-widgets/code.asciidoc[]
  99. include::{es-repo-dir}/tab-widgets/register-fs-repo-widget.asciidoc[]
  100. [discrete]
  101. [[snapshots-read-only-repository]]
  102. === Read-only URL repository
  103. If you register the same snapshot repository with multiple clusters, only one
  104. cluster should have write access to the repository. Having multiple clusters
  105. write to the repository at the same time risks corrupting the contents of the
  106. repository.
  107. To reduce this risk, you can use URL repositories (`"type": "url"`) to give one
  108. or more clusters read-only access to a shared file system repository. As URL
  109. repositories are always read-only, they are a safer and more convenient
  110. alternative to registering a read-only shared filesystem repository.
  111. The URL specified in the `url` parameter should point to the root of the shared
  112. filesystem repository.
  113. [source,console]
  114. ----
  115. PUT /_snapshot/my_read_only_url_repository
  116. {
  117. "type": "url",
  118. "settings": {
  119. "url": "file:/mount/backups/my_fs_backup_location"
  120. }
  121. }
  122. ----
  123. // TEST[skip:no access to url file path]
  124. The `url` parameter supports the following protocols:
  125. * `file`
  126. * `ftp`
  127. * `http`
  128. * `https`
  129. * `jar`
  130. URLs using the `file` protocol must point to the location of a shared filesystem
  131. accessible to all master and data nodes in the cluster. This location must be
  132. registered in the `path.repo` setting, similar to a
  133. <<snapshots-filesystem-repository,shared file system repository>>.
  134. URLs using the `ftp`, `http`, or `https` protocols must be explicitly allowed with the
  135. `repositories.url.allowed_urls` setting. This setting supports wildcards (`*`)
  136. in place of a host, path, query, or fragment in the URL. For example:
  137. [source,yaml]
  138. ----
  139. repositories.url.allowed_urls: ["http://www.example.org/root/*", "https://*.mydomain.com/*?*#*"]
  140. ----
  141. NOTE: URLs using the `ftp`, `http`, `https`, or `jar` protocols do not need to
  142. be registered in the `path.repo` setting.
  143. [discrete]
  144. [role="xpack"]
  145. [testenv="basic"]
  146. [[snapshots-source-only-repository]]
  147. === Source only repository
  148. A source repository enables you to create minimal, source-only snapshots that take up to 50% less space on disk.
  149. Source only snapshots contain stored fields and index metadata. They do not include index or doc values structures
  150. and are not searchable when restored. After restoring a source-only snapshot, you must <<docs-reindex,reindex>>
  151. the data into a new index.
  152. Source repositories delegate to another snapshot repository for storage.
  153. [IMPORTANT]
  154. ==================================================
  155. Source only snapshots are only supported if the `_source` field is enabled and no source-filtering is applied.
  156. When you restore a source only snapshot:
  157. * The restored index is read-only and can only serve `match_all` search or scroll requests to enable reindexing.
  158. * Queries other than `match_all` and `_get` requests are not supported.
  159. * The mapping of the restored index is empty, but the original mapping is available from the types top
  160. level `meta` element.
  161. ==================================================
  162. When you create a source repository, you must specify the type and name of the delegate repository
  163. where the snapshots will be stored:
  164. [source,console]
  165. -----------------------------------
  166. PUT _snapshot/my_src_only_repository
  167. {
  168. "type": "source",
  169. "settings": {
  170. "delegate_type": "fs",
  171. "location": "my_backup_location"
  172. }
  173. }
  174. -----------------------------------
  175. // TEST[continued]
  176. [discrete]
  177. [[snapshots-repository-plugins]]
  178. === Repository plugins
  179. Other repository backends are available in these official plugins:
  180. * {plugins}/repository-s3.html[repository-s3] for S3 repository support
  181. * {plugins}/repository-hdfs.html[repository-hdfs] for HDFS repository support in Hadoop environments
  182. * {plugins}/repository-azure.html[repository-azure] for Azure storage repositories
  183. * {plugins}/repository-gcs.html[repository-gcs] for Google Cloud Storage repositories
  184. [discrete]
  185. [[snapshots-repository-verification]]
  186. === Repository verification
  187. When a repository is registered, it's immediately verified on all master and data nodes to make sure that it is functional
  188. on all nodes currently present in the cluster. The `verify` parameter can be used to explicitly disable the repository
  189. verification when registering or updating a repository:
  190. [source,console]
  191. -----------------------------------
  192. PUT /_snapshot/my_unverified_backup?verify=false
  193. {
  194. "type": "fs",
  195. "settings": {
  196. "location": "my_unverified_backup_location"
  197. }
  198. }
  199. -----------------------------------
  200. // TEST[continued]
  201. The verification process can also be executed manually by running the following command:
  202. [source,console]
  203. -----------------------------------
  204. POST /_snapshot/my_unverified_backup/_verify
  205. -----------------------------------
  206. // TEST[continued]
  207. It returns a list of nodes where repository was successfully verified or an error message if verification process failed.
  208. If desired, you can also test a repository more thoroughly using the
  209. <<repo-analysis-api,Repository analysis API>>.
  210. [discrete]
  211. [[snapshots-repository-cleanup]]
  212. === Repository cleanup
  213. Repositories can over time accumulate data that is not referenced by any existing snapshot. This is a result of the data safety guarantees
  214. the snapshot functionality provides in failure scenarios during snapshot creation and the decentralized nature of the snapshot creation
  215. process. This unreferenced data does in no way negatively impact the performance or safety of a snapshot repository but leads to higher
  216. than necessary storage use. In order to clean up this unreferenced data, users can call the cleanup endpoint for a repository which will
  217. trigger a complete accounting of the repositories contents and subsequent deletion of all unreferenced data that was found.
  218. [source,console]
  219. -----------------------------------
  220. POST /_snapshot/my_repository/_cleanup
  221. -----------------------------------
  222. // TEST[continued]
  223. The response to a cleanup request looks as follows:
  224. [source,console-result]
  225. --------------------------------------------------
  226. {
  227. "results": {
  228. "deleted_bytes": 20,
  229. "deleted_blobs": 5
  230. }
  231. }
  232. --------------------------------------------------
  233. Depending on the concrete repository implementation the numbers shown for bytes free as well as the number of blobs removed will either
  234. be an approximation or an exact result. Any non-zero value for the number of blobs removed implies that unreferenced blobs were found and
  235. subsequently cleaned up.
  236. Please note that most of the cleanup operations executed by this endpoint are automatically executed when deleting any snapshot from a
  237. repository. If you regularly delete snapshots, you will in most cases not get any or only minor space savings from using this functionality
  238. and should lower your frequency of invoking it accordingly.
  239. [discrete]
  240. [[snapshots-repository-backup]]
  241. === Repository backup
  242. You may wish to make an independent backup of your repository, for instance so
  243. that you have an archive copy of its contents that you can use to recreate the
  244. repository in its current state at a later date.
  245. You must ensure that {es} does not write to the repository while you are taking
  246. the backup of its contents. You can do this by unregistering it, or registering
  247. it with `readonly: true`, on all your clusters. If {es} writes any data to the
  248. repository during the backup then the contents of the backup may not be
  249. consistent and it may not be possible to recover any data from it in future.
  250. Alternatively, if your repository supports it, you may take an atomic snapshot
  251. of the underlying filesystem and then take a backup of this filesystem
  252. snapshot. It is very important that the filesystem snapshot is taken
  253. atomically.
  254. WARNING: You cannot use filesystem snapshots of individual nodes as a backup
  255. mechanism. You must use the {es} snapshot and restore feature to copy the
  256. cluster contents to a separate repository. Then, if desired, you can take a
  257. filesystem snapshot of this repository.