register-repository.asciidoc 12 KB

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