Updated on 2026-09-20 GMT+08:00

Adding a Snapshot Policy

Function

This API is used to configure a snapshot policy.

Calling Method

For details, see Calling APIs.

Authorization Information

Each account has all the permissions required to call all APIs, but IAM users must be assigned the required permissions.

  • If you are using role/policy-based authorization, see Permissions Policies and Supported Actions for details on the required permissions.
  • If you are using identity policy-based authorization, the following identity policy-based permissions are required.

    Action

    Access Level

    Resource Type (*: required)

    Condition Key

    Alias

    Dependencies

    dws:cluster:createSnapshotPolicy

    Write

    cluster *

    • g:ResourceTag/<tag-key>

    • g:EnterpriseProjectId

    • dws:BackupToEdge

    dws:cluster:setAutomatedSnapshot

    -

URI

PUT /v2/{project_id}/clusters/{cluster_id}/snapshot-policies

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Definition

Project ID. To obtain the value, see Obtaining a Project ID.

Constraints

N/A

Range

N/A

Default Value

N/A

cluster_id

Yes

String

Definition

Cluster ID. For details about how to obtain the value, see Obtaining the Cluster ID.

Constraints

The value must be a valid DWS cluster ID.

Range

It is a 36-digit UUID.

Default Value

N/A

Request Parameters

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

keep_day

No

Integer

Definition

Retention days.

Range

1 to 31.

backup_strategies

No

Array of BackupStrategyRequest objects

Definition

Policy list. This parameter is mandatory when you add a policy.

Range

N/A

device_name

No

String

Definition

Backup device. OBS, NBU, and NFS are supported.

Range

N/A

server_port

No

String

Definition

Port of the NBU backup media. This parameter is mandatory when the backup medium is NBU.

Range

N/A

backup_param

No

String

Definition

NBU backup parameters. This parameter is mandatory when the backup medium is NBU.

Range

N/A

server_ips

No

Array of strings

Definition

IP address of the backup media. This parameter is mandatory when the backup medium is NBU or NFS. If the backup medium is NBU, it indicates the address of the NBU server. If the backup medium is NFS, it indicates the address of the NFS server.

Range

N/A

auto_backup

No

Boolean

Definition:

Whether auto backup is supported

Range:

None

Table 3 BackupStrategyRequest

Parameter

Mandatory

Type

Description

policy_id

No

String

Definition

Policy ID.

Range

N/A

policy_name

No

String

Definition

Policy name. This parameter is mandatory when you add a backup policy. The policy name must be unique, consist of 4 to 92 characters, and start with a letter. It is case-insensitive and can contain only letters, digits, hyphens (-), and underscores (_).

Range

N/A

backup_strategy

No

String

Definition

Execution policy. This parameter is mandatory when you add a backup policy. The value must comply with the cron expression format.

Range

N/A

backup_type

No

String

Definition

Backup type.

Range

full: full backup

increment: incremental backup

backup_level

No

String

Definition:

Backup level.

Range:

cluster

schema

table

next_fire_time

No

String

Definition:

Next triggering time

Range:

None

update_time

No

String

Definition:

Update time

Range:

None

time_zone_offset

No

Integer

Definition:

Time zone offset

Range:

None

backup_database

No

String

Definition:

Database to be backed up

Range:

None

backup_schema_list

No

String

Definition:

List of database schemas to be backed up

Range:

None

backup_table_list

No

String

Definition:

List of database tables to be backed up

Range:

None

Response Parameters

Status code: 200

Request succeeded.

None

Example Requests

Add a cluster-level full snapshot policy named test (A snapshot is created at 03:00 every Monday to Sunday).

PUT https://{Endpoint}/v2/89cd04f168b84af6be287f71730fdb4b/clusters/4ca46bf1-5c61-48ff-b4f3-0ad4e5e3ba90/snapshot-policies

{
  "backup_strategies" : [ {
    "policy_name" : "test",
    "backup_level" : "cluster",
    "backup_type" : "full",
    "backup_strategy" : "0 0 3 ? * 1,2,3,4,5,6,7",
    "time_zone_offset" : 0
  } ]
}

Example Responses

Status code: 200

Request succeeded.

{ }

SDK Sample Code

The SDK sample code is as follows.

Add a cluster-level full snapshot policy named test (A snapshot is created at 03:00 every Monday to Sunday).

 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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.dws.v2.region.DwsRegion;
import com.huaweicloud.sdk.dws.v2.*;
import com.huaweicloud.sdk.dws.v2.model.*;

import java.util.List;
import java.util.ArrayList;

public class CreateSnapshotPolicySolution {

    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);

        DwsClient client = DwsClient.newBuilder()
                .withCredential(auth)
                .withRegion(DwsRegion.valueOf("<YOUR REGION>"))
                .build();
        CreateSnapshotPolicyRequest request = new CreateSnapshotPolicyRequest();
        request.withClusterId("{cluster_id}");
        CreateSnapshotPolicyRequestBody body = new CreateSnapshotPolicyRequestBody();
        List<BackupStrategyRequest> listbodyBackupStrategies = new ArrayList<>();
        listbodyBackupStrategies.add(
            new BackupStrategyRequest()
                .withPolicyName("test")
                .withBackupStrategy("0 0 3 ? * 1,2,3,4,5,6,7")
                .withBackupType("full")
                .withBackupLevel("cluster")
                .withTimeZoneOffset(0)
        );
        body.withBackupStrategies(listbodyBackupStrategies);
        request.withBody(body);
        try {
            CreateSnapshotPolicyResponse response = client.createSnapshotPolicy(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());
        }
    }
}

Add a cluster-level full snapshot policy named test (A snapshot is created at 03:00 every Monday to Sunday).

 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
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkdws.v2.region.dws_region import DwsRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkdws.v2 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 = DwsClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(DwsRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = CreateSnapshotPolicyRequest()
        request.cluster_id = "{cluster_id}"
        listBackupStrategiesbody = [
            BackupStrategyRequest(
                policy_name="test",
                backup_strategy="0 0 3 ? * 1,2,3,4,5,6,7",
                backup_type="full",
                backup_level="cluster",
                time_zone_offset=0
            )
        ]
        request.body = CreateSnapshotPolicyRequestBody(
            backup_strategies=listBackupStrategiesbody
        )
        response = client.create_snapshot_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)

Add a cluster-level full snapshot policy named test (A snapshot is created at 03:00 every Monday to Sunday).

 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    dws "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dws/v2"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dws/v2/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dws/v2/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, err := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        SafeBuild()

    if err != nil {
        fmt.Println(err)
        return
    }

    hcClient, err := dws.DwsClientBuilder().
         WithRegion(region.ValueOf("<YOUR REGION>")).
         WithCredential(auth).
         SafeBuild()


    if err != nil {
        fmt.Println(err)
        return
    }

    client := dws.NewDwsClient(hcClient)

    request := &model.CreateSnapshotPolicyRequest{}
	request.ClusterId = "{cluster_id}"
	policyNameBackupStrategies:= "test"
	backupStrategyBackupStrategies:= "0 0 3 ? * 1,2,3,4,5,6,7"
	backupTypeBackupStrategies:= "full"
	backupLevelBackupStrategies:= "cluster"
	timeZoneOffsetBackupStrategies:= int32(0)
	var listBackupStrategiesbody = []model.BackupStrategyRequest{
        {
            PolicyName: &policyNameBackupStrategies,
            BackupStrategy: &backupStrategyBackupStrategies,
            BackupType: &backupTypeBackupStrategies,
            BackupLevel: &backupLevelBackupStrategies,
            TimeZoneOffset: &timeZoneOffsetBackupStrategies,
        },
    }
	request.Body = &model.CreateSnapshotPolicyRequestBody{
		BackupStrategies: &listBackupStrategiesbody,
	}
	response, err := client.CreateSnapshotPolicy(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

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.

400

Request error.

401

Authentication failed.

403

You do not have required permissions.

404

No resources found.

500

Internal server error.

503

Service unavailable.