Create or Update Snapshot Repository API
Introduced 1.0
Registers a new snapshot repository or updates an existing one.
Snapshot repositories can be of the following types:
-
File system (
fs): For more information about creating anfsrepository, see Register repository shared file system. -
Amazon Simple Storage Service (Amazon S3) bucket (
s3): For more information about creating ans3repository, see Register repository Amazon S3. -
Hadoop Distributed File System (HDFS) (
hdfs): For more information about creating anhdfsrepository, see Register an HDFS repository.
For more information about creating a repository, see Register repository.
To update an existing repository, send a request containing the repository’s full definition. The new settings replace all existing settings, so any setting that you don’t include in the request is reset to its default value.
Because the snapshot format can change between major versions, we recommend registering a separate repository for each major version of OpenSearch. For more information, see Sharing a repository between clusters.
Endpoints
POST /_snapshot/{repository}
PUT /_snapshot/{repository}
Path parameters
The following table lists the available path parameters.
| Parameter | Data type | Description |
|---|---|---|
repository | String | The repository name. |
Query parameters
The following table lists the available query parameters. All query parameters are optional.
| Parameter | Data type | Description |
|---|---|---|
cluster_manager_timeout | Time | The amount of time to wait for a response from the cluster manager node. Default is 30s. |
timeout | Time | The amount of time to wait for a response. Default is 30s. |
verify | Boolean | Whether to verify that the repository is accessible from all cluster manager and data nodes before registering it. If false, OpenSearch registers the repository without checking it. To verify the repository later, use the Verify Snapshot Repository API. Default is true. |
Request body fields
The following table lists the available request body fields.
| Field | Data type | Description |
|---|---|---|
type | String | The repository type. Valid values are fs, s3, hdfs, azure, and url. The s3, hdfs, and azure types require the corresponding repository plugin. For information about azure repositories, see Microsoft Azure. Required. |
settings | Object | The repository settings. The valid settings depend on the repository type and are listed in the following sections. Required. |
Common parameters
The following table lists parameters that can be used with both the fs and s3 repositories.
| Request field | Description |
|---|---|
prefix_mode_verification | When enabled, adds a hashed value of a random seed to the prefix for repository verification. For remote-store-enabled clusters, you can add the setting.prefix_mode_verification setting to the node attributes for the supplied repository. This field works with both new and existing repositories. Optional. |
shard_path_type | Controls the path structure of shard-level blobs. Supported values are FIXED, HASHED_PREFIX, and HASHED_INFIX. For more information about each value, see shard_path_type values. Default is HASHED_PREFIX. Optional. |
shard_path_type values
The following values are supported in the shard_path_type setting:
FIXED: Keeps the path structure in the existing hierarchical manner, such as<ROOT>/<BASE_PATH>/indices/<index-id>/0/<SHARD_BLOBS>.HASHED_PREFIX: Prepends a hashed prefix at the start of the path for each unique shard ID, for example,<ROOT>/<HASH-OF-INDEX-ID-AND-SHARD-ID>/<BASE_PATH>/indices/<index-id>/0/<SHARD_BLOBS>.HASHED_INFIX: Appends a hashed prefix after the base path for each unique shard ID, for example,<ROOT>/<BASE-PATH>/<HASH-OF-INDEX-ID-AND-SHARD-ID>/indices/<index-id>/0/<SHARD_BLOBS>. The hash method used isFNV_1A_COMPOSITE_1, which uses theFNV1ahash function and generates a custom-encoded 64-bit hash value that scales well with most remote store options.FNV1atakes the most significant 6 bits to create a URL-safe Base64 character and the next 14 bits to create a binary string.
fs repository
The following table lists the request fields for fs repositories.
| Request field | Description |
|---|---|
location | The file system directory for snapshots, such as a mounted directory from a file server or a Samba share. The file system must be mounted at the same path on all cluster manager and data nodes, and the location must be listed in the path.repo setting. A relative path is resolved against the first path.repo directory. Required. |
chunk_size | Breaks large files into chunks during snapshot operations (for example, 64mb or 1gb), which is important for cloud storage providers and far less important for shared file systems. Default is null (unlimited). Optional. |
compress | Whether to compress metadata files. This setting does not affect data files, which might already be compressed, depending on your index settings. Default is false. Optional. |
max_restore_bytes_per_sec | The maximum rate per node at which snapshots are restored. Default is 0 (unlimited). The restore rate is also subject to indices.recovery.max_bytes_per_sec (by default, 40mb). Optional. |
max_snapshot_bytes_per_sec | The maximum rate per node at which snapshots are taken. Default is 40 MB per second (40mb). Optional. |
remote_store_index_shallow_copy | Determines whether the snapshots of the remote store indexes are captured as shallow copies. Default is false. |
shallow_snapshot_v2 | Determines whether the snapshots of the remote store indexes are captured as a shallow copy v2. Default is false. |
readonly | Whether the repository is read-only. A read-only repository can list and restore snapshots but can’t create them. If you register the same repository on multiple clusters, only one cluster should write to it, and all other clusters should register it with readonly set to true. For more information, see Sharing a repository between clusters. Default is false. Optional. |
s3 repository
The following table lists the request fields for s3 repositories.
| Request field | Description |
|---|---|
base_path | The path within the bucket in which you want to store snapshots (for example, my/snapshot/directory). Do not include the s3:// prefix. Optional. If not specified, snapshots are stored in the S3 bucket root. |
bucket | The name of the S3 bucket, without the s3:// prefix. Required. |
region | The AWS Region in which the S3 bucket is located. Optional. If missing, values of s3.client.default.region from opensearch.yml are used. |
endpoint | The S3 bucket endpoint. If not specified, the value of s3.client.default.endpoint from opensearch.yml is used. If neither is set, the endpoint is determined from the region. Set this field when you use an S3-compatible storage service or need a specific endpoint, for example, https://s3.us-west-2.amazonaws.com for us-west-2. Optional. |
buffer_size | The threshold beyond which chunks (of chunk_size) should be broken into pieces (of buffer_size) and sent to S3 using a different API. Default is the smaller of two values: 100 MB or 5% of the Java heap. Valid values are between 5mb and 5gb. We don’t recommend changing this option. |
canned_acl | S3 has several canned ACLs that the repository-s3 plugin can add to objects as it creates them in S3. Default is private. Optional. |
chunk_size | Breaks files into chunks during snapshot operations (for example, 64mb, 1gb), which is important for cloud storage providers and far less important for shared file systems. Default is 1gb. Optional. |
client | When specifying client settings (for example, s3.client.default.access_key), you can use a string other than default (for example, s3.client.backup-role.access_key). If you used an alternate name, change this value to match. Default and recommended value is default. Optional. |
compress | Whether to compress metadata files. This setting does not affect data files, which might already be compressed, depending on your index settings. Default is false. Optional. |
disable_chunked_encoding | Disables chunked encoding for compatibility with some storage services. Default is false. Optional. |
max_restore_bytes_per_sec | The maximum rate per node at which snapshots are restored. Default is 0 (unlimited). The restore rate is also subject to indices.recovery.max_bytes_per_sec (by default, 40mb). Optional. |
max_snapshot_bytes_per_sec | The maximum rate per node at which snapshots are taken. Default is 40 MB per second (40mb). Optional. |
readonly | Whether the repository is read-only. A read-only repository can list and restore snapshots but can’t create them. If you register the same repository on multiple clusters, only one cluster should write to it, and all other clusters should register it with readonly set to true. For more information, see Sharing a repository between clusters. Default is false. Optional. |
remote_store_index_shallow_copy | Determines whether the snapshots of the remote store indexes are captured as shallow copies. Default is false. |
s3_async_client_type | The asynchronous HTTP client that the repository-s3 plugin uses when it uploads data to this repository. Valid values are crt (the AWS Common Runtime client) and netty (the Netty NIO client). For more information, see s3_async_client_type. Default is crt. Optional. |
shallow_snapshot_v2 | Determines whether the snapshots of the remote store indexes are captured as a shallow copy v2. Default is false. |
storage_class | Specifies the S3 storage class for the snapshot files. Default is standard. Do not use the glacier and deep_archive storage classes. Optional. |
server_side_encryption_type | Specifies the S3 server-side encryption types. Supported values are AES256 (SSE-S3), aws:kms (SSE-AWS Key Management Service (KMS)), and bucket_default (bucket default encryption). Default is bucket_default. |
server_side_encryption_kms_key_id | Specifies the AWS KMS key to be used if S3 SSE-KMS is selected by setting the aws:kms encryption type. Required if aws:kms is set as the server_side_encryption_type. |
server_side_encryption_bucket_key_enabled | Specifies whether S3 Bucket Keys should be used when using S3 SSE-KMS. Optional. |
server_side_encryption_encryption_context | Specifies any additional encryption context that should be used when using S3 SSE-KMS. This setting value must be formatted as a JSON object. Optional. |
expected_bucket_owner | Specifies the AWS account ID of the expected S3 bucket owner. This setting can be used for verifying bucket ownership. Optional. |
The server_side_encryption setting was removed in OpenSearch 3.1.0. S3 applies server-side encryption as the base level of encryption for all S3 buckets. Because this encryption cannot be disabled, the repository setting had no effect. For more information, see Protecting data with server-side encryption.
s3_async_client_type
s3_async_client_type applies to a single repository, so set it in the repository’s settings block. The repository-s3 plugin also registers s3_async_client_type as a node setting, so a node starts successfully with the setting in opensearch.yml and the Nodes Info API returns it, but the plugin reads the value only from the repository definition. A repository that does not set s3_async_client_type uses crt, even when opensearch.yml specifies netty.
If the AWS Common Runtime native library is not available on the node’s platform, the plugin logs a warning and uses the Netty client.
To confirm which client a repository uses, enable DEBUG logging for the org.opensearch.repositories.s3.S3AsyncService logger and look for the S3 Http client type message.
hdfs repository
The following table lists the request fields for hdfs repositories.
| Request field | Description |
|---|---|
uri | The HDFS URI in the hdfs://<HOST>:<PORT>/ format. The URI must not contain a path. Specify the path in the path field. Required. |
path | The path within HDFS where you want to store snapshots (for example, /my/snapshot/directory). Required. |
security.principal | The Kerberos principal to use when connecting to HDFS. Optional. |
conf.<key> | Additional HDFS client configuration settings (for example, core-site.xml or hdfs-site.xml). Optional. |
url repository
A url repository is read-only: you can list and restore snapshots from it, but you can’t create snapshots in it. Use a url repository to give a cluster read-only access to snapshots that another cluster writes to a shared file system repository.
The following table lists the request fields for url repositories.
| Request field | Description |
|---|---|
url | The URL of the root of the repository. To give read-only access to a shared file system repository, the URL must point to that repository’s location, not to a parent directory. Supported protocols are file, ftp, http, https, and jar. A file URL must point to a location listed in the path.repo setting on all cluster manager and data nodes. An ftp, http, or https URL must match an entry in the repositories.url.allowed_urls setting. For more information, see Node-level repository settings. Required. |
Example requests
The following examples demonstrate how to register different repository types.
fs
The following example registers an fs repository using the local directory /mnt/snapshots as location:
PUT /_snapshot/my-fs-repository
{
"type": "fs",
"settings": {
"location": "/mnt/snapshots"
}
}response = client.snapshot.create_repository(
repository = "my-fs-repository",
body = {
"type": "fs",
"settings": {
"location": "/mnt/snapshots"
}
}
)s3
The following request registers a new S3 repository called my-opensearch-repo in an existing bucket called my-open-search-bucket. Because the request sets base_path, snapshots are stored in the my/snapshot/directory path within the bucket:
PUT /_snapshot/my-opensearch-repo
{
"type": "s3",
"settings": {
"bucket": "my-open-search-bucket",
"base_path": "my/snapshot/directory"
}
}response = client.snapshot.create_repository(
repository = "my-opensearch-repo",
body = {
"type": "s3",
"settings": {
"bucket": "my-open-search-bucket",
"base_path": "my/snapshot/directory"
}
}
)The following request registers a new S3 repository called my-opensearch-repo in an existing bucket called my-open-search-bucket. Because the request sets base_path, snapshots are stored in the my/snapshot/directory path within the bucket. Additionally, this repository is configured to use SSE-KMS, and the expected bucket owner AWS account ID is 123456789000:
PUT /_snapshot/my-opensearch-repo
{
"type": "s3",
"settings": {
"bucket": "my-open-search-bucket",
"base_path": "my/snapshot/directory",
"server_side_encryption_type": "aws:kms",
"server_side_encryption_kms_key_id": "arn:aws:kms:us-east-1:123456789000:key/kms-key-id",
"server_side_encryption_encryption_context": "{\"additional-enc-ctx\": \"sample-context\"}",
"expected_bucket_owner": "123456789000"
}
}response = client.snapshot.create_repository(
repository = "my-opensearch-repo",
body = {
"type": "s3",
"settings": {
"bucket": "my-open-search-bucket",
"base_path": "my/snapshot/directory",
"server_side_encryption_type": "aws:kms",
"server_side_encryption_kms_key_id": "arn:aws:kms:us-east-1:123456789000:key/kms-key-id",
"server_side_encryption_encryption_context": "{\"additional-enc-ctx\": \"sample-context\"}",
"expected_bucket_owner": "123456789000"
}
}
)hdfs
The following request registers a new HDFS repository using the HDFS URI hdfs://namenode:8020 and the HDFS file system path /opensearch/snapshots:
PUT /_snapshot/my-hdfs-repository
{
"type": "hdfs",
"settings": {
"uri": "hdfs://namenode:8020",
"path": "/opensearch/snapshots"
}
}response = client.snapshot.create_repository(
repository = "my-hdfs-repository",
body = {
"type": "hdfs",
"settings": {
"uri": "hdfs://namenode:8020",
"path": "/opensearch/snapshots"
}
}
)url
The following request registers a read-only url repository for the shared file system location /mnt/snapshots:
PUT /_snapshot/my-url-repository
{
"type": "url",
"settings": {
"url": "file:/mnt/snapshots"
}
}response = client.snapshot.create_repository(
repository = "my-url-repository",
body = {
"type": "url",
"settings": {
"url": "file:/mnt/snapshots"
}
}
)Example response
Upon success, the following JSON object is returned:
{
"acknowledged": true
}
To verify that the repository was registered, use the Get Snapshot Repository API, passing the repository name as the repository path parameter.
Required permissions
If you use the Security plugin, make sure you have the appropriate permissions: cluster:admin/repository/put.