Querying the Automatic Snapshot Creation Policy
Function
CSS allows you to use snapshots to back up and restore Elasticsearch cluster data. By storing a snapshot in an OBS bucket, you save a point-in-time copy of the cluster's data. By restoring this snapshot, you can restore the cluster to a previous state. There are two ways to create snapshots to back up a CSS cluster: automatic and manual. This API is used to query the automatic snapshot creation policy.
-
Automatic snapshot creation: Snapshots are automatically created daily or weekly based on a preset time schedule, ensuring ongoing data protection. By configuring an automatic snapshot policy, you reduce manual operations while improving backup reliability and efficiency.
-
Manual snapshot creation: You create snapshots manually for special occasions, for example, prior to a high-risk operation (such as a cluster upgrade). This ensures you can restore data using snapshots in case anything should go wrong. Manual snapshots provide additional flexibility.
Calling Method
For details, see Calling APIs.
URI
GET /v1.0/{project_id}/clusters/{cluster_id}/index_snapshot/policy
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
project_id |
Yes |
String |
Definition: Project ID. For details about how to obtain the project ID and name, see Obtaining the Project ID and Name. Constraints: N/A Value range: Project ID of the account. Default value: N/A |
|
cluster_id |
Yes |
String |
Definition: ID of the cluster where snapshots are to be automatically created. For details about how to obtain the cluster ID, see Obtaining the Cluster ID. Constraints: N/A Value range: Cluster ID. Default value: N/A |
Request Parameters
None
Response Parameters
Status code: 200
|
Parameter |
Type |
Description |
|---|---|---|
|
keepday |
Integer |
Definition: Customize the number of snapshots to be retained. Expired snapshots will be automatically deleted on the half hour. The deletion policy applies only to automated snapshots that are executed at the same frequency as the current automatic snapshot creation policy. Value range: 1–90 |
|
period |
String |
Definition: Time when a snapshot is created every day. Value range: Snapshots can only be created on the hour. The time format is the time followed by the time zone, specifically, HH:mm z. In the format, HH:mm refers to the hour time and z refers to the time zone. For example, 00:00 GMT+08:00 and 01:00 GMT+08:00. |
|
frequency |
String |
Definition: Frequency of automatically creating snapshots. Value range:
|
|
prefix |
String |
Definition: Prefix of the name of an automatically created snapshot. A snapshot name consists of the snapshot name prefix and timestamp, for example, snapshot-1566921603720. Value range: Enter up to 32 characters and start with a lowercase letter. Lowercase letters, digits, hyphens (-), and underscores (_) are allowed. |
|
bucket |
String |
Definition: Name of the OBS bucket that stores snapshots. Value range: N/A |
|
basePath |
String |
Definition: Storage path of the snapshot in the OBS bucket. Value range:
|
|
agency |
String |
Definition: Agency name. Select an IAM agency to grant the current account the permission to access and use OBS. To store snapshots to an OBS bucket, you must have the required OBS access permissions. Value range: N/A |
|
enable |
String |
Definition: Whether to enable automatic snapshot creation. Value range:
|
|
indices |
String |
Definition: Name of the index to be backed up.
Value range: The value can contain 0 to 1,024 characters. It cannot contain uppercase letters, spaces, or the following special characters: "<|>/? |
|
snapshotCmkId |
String |
Definition: Snapshot ID. Value range: N/A |
|
maxSnapshotBytesPerSeconds |
String |
Definition: This parameter sets the maximum backup speed per node (bytes per second). When it is exceeded, flow control is triggered to prevent excessive resource usage and ensure system stability. The actual backup speed may not reach the configured value, as it depends on many factors, such as OBS performance and disk I/O. Value range: The following values and formats are allowed:
The number ranges from 0 to 9999. The unit can be k, kb, m, mb, g, gb, t, tb, p, pb, or b (case-insensitive). Setting this parameter to 0mb, 0, -1 means there is no speed limit. An overly high backup speed may lead to excessive resource usage, which may impact system stability. |
|
maxRestoreBytesPerSeconds |
String |
Definition: This parameter sets the maximum recovery speed per node (bytes per second). When it is exceeded, flow control is triggered to prevent excessive resource usage and ensure system stability. The actual recovery speed may not reach the configured value, as it depends on many factors, such as OBS performance and disk I/O. Constraints: For OpenSearch clusters and Elasticsearch clusters later than 7.6.2, the recovery speed is also limited by the indices.recovery.max_bytes_per_sec parameter. If Maximum recovery speed (per second) is lower than indices.recovery.max_bytes_per_sec, flow control is triggered when the former is reached. If Maximum recovery speed (per second) is higher than indices.recovery.max_bytes_per_sec, flow control is triggered when the latter is reached. Value range: The following values and formats are allowed:
The number ranges from 0 to 9999. The unit can be k, kb, m, mb, g, gb, t, tb, p, pb, or b (case-insensitive). Setting this parameter to 0mb, 0, -1 means there is no speed limit. (However, for OpenSearch clusters and Elasticsearch clusters later than 7.6.2, the recovery speed is also limited by the indices.recovery.max_bytes_per_sec parameter.) An overly high recovery speed may lead to excessive resource usage, which may impact system stability. Default value: For Elasticsearch clusters of 7.6.2 or earlier, the default setting is 40mb. For OpenSearch clusters and Elasticsearch clusters later than 7.6.2, the default setting is no limit, but the recovery speed is still limited by the indices.recovery.max_bytes_per_sec parameter. If this parameter is left blank, the default setting is used. |
Example Requests
Query the automatic snapshot creation policy.
GET https://{Endpoint}/v1.0/{project_id}/clusters/4f3deec3-efa8-4598-bf91-560aad1377a3/index_snapshot/policy
Example Responses
Status code: 200
Request succeeded.
{
"keepday" : 2,
"period" : "16:00 GMT+08:00",
"frequency" : "DAY",
"prefix" : "snapshot",
"bucket" : "es-backup",
"basePath" : "css_repository/tests",
"agency" : "usearch",
"enable" : "true",
"indices" : "*",
"snapshotCmkId" : null,
"maxSnapshotBytesPerSeconds" : "40MB",
"maxRestoreBytesPerSeconds" : "0MB"
}
SDK Sample Code
The SDK sample code is as follows.
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.css.v1.region.CssRegion; import com.huaweicloud.sdk.css.v1.*; import com.huaweicloud.sdk.css.v1.model.*; public class ShowAutoCreatePolicySolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); CssClient client = CssClient.newBuilder() .withCredential(auth) .withRegion(CssRegion.valueOf("<YOUR REGION>")) .build(); ShowAutoCreatePolicyRequest request = new ShowAutoCreatePolicyRequest(); request.withClusterId("{cluster_id}"); try { ShowAutoCreatePolicyResponse response = client.showAutoCreatePolicy(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } |
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcss.v1.region.css_region import CssRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkcss.v1 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = CssClient.new_builder() \ .with_credentials(credentials) \ .with_region(CssRegion.value_of("<YOUR REGION>")) \ .build() try: request = ShowAutoCreatePolicyRequest() request.cluster_id = "{cluster_id}" response = client.show_auto_create_policy(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
Go
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" css "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/css/v1" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/css/v1/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/css/v1/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := css.NewCssClient( css.CssClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.ShowAutoCreatePolicyRequest{} request.ClusterId = "{cluster_id}" response, err := client.ShowAutoCreatePolicy(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
More
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
Status Codes
|
Status Code |
Description |
|---|---|
|
200 |
Request succeeded. |
|
406 |
The server could not fulfill the request according to the content characteristics of the request. |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot