文档首页> 云备份 CBR> API参考> API> 策略> 查询策略列表
更新时间:2024-03-12 GMT+08:00
分享

查询策略列表

功能介绍

查询策略列表

调用方法

请参见如何调用API

URI

GET /v3/{project_id}/policies

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID

表2 Query参数

参数

是否必选

参数类型

描述

operation_type

String

策略类型:备份(backup)、复制(replication)

vault_id

String

存储库ID

请求参数

表3 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

用户Token。 通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。

响应参数

状态码: 200

表4 响应Body参数

参数

参数类型

描述

policies

Array of Policy objects

策略列表

count

Integer

策略总数

表5 Policy

参数

参数类型

描述

enabled

Boolean

策略是否启用

id

String

策略ID

name

String

策略名称

operation_definition

PolicyoODCreate object

策略属性

operation_type

String

保护类型:备份(backup)、复制(replication)。

trigger

PolicyTriggerResp object

策略时间调度规则

associated_vaults

Array of PolicyAssociateVault objects

关联的存储库

表6 PolicyoODCreate

参数

参数类型

描述

day_backups

Integer

保留日备个数,该备份不受保留最大备份数限制。取值为0到100。若选择该参数,则timezone 也必选。

最小值:0

最大值:100

destination_project_id

String

复制的目标项目ID,仅在跨区域复制时才会使用并且必须指定。

destination_region

String

复制的目标区域,仅在跨区域复制时才会使用并且必须指定。长度限制:0- 255,只能由字母、数字、“_”、“-”组成

enable_acceleration

Boolean

跨区域复制时,是否启用加速从而缩减复制的时间,如果不指定,默认不启用加速。

max_backups

Integer

单个备份对象自动备份的最大备份数。取值为-1或0-99999。-1代表不按备份数清理。若该字段和retention_duration_days字段同时为空,备份会永久保留。

最小值:1

最大值:99999

缺省值:-1

month_backups

Integer

保留月备个数,该备份不受保留最大备份数限制。取值为0到100。若选择该参数,则timezone 也必选。

最小值:0

最大值:100

retention_duration_days

Integer

备份保留时长,单位天。最长支持99999天。-1代表不按时间清理。若该字段和max_backups 参数同时为空,备份会永久保留。

最小值:1

最大值:99999

缺省值:-1

timezone

String

用户所在时区,格式形如UTC+08:00, 若选择年备,月备,周备,日备中任一参数,则该参数不能为空。

week_backups

Integer

保留周备个数,该备份不受保留最大备份数限制。取值为0到100。若选择该参数,则timezone 也必选。

year_backups

Integer

保留年备个数,该备份不受保留最大备份数限制。取值为0到100。若选择该参数,则timezone 也必选。

最小值:0

最大值:100

full_backup_interval

Integer

每间隔多少次执行一次全量备份,当取值为 -1 时,不执行全量备份 最小值:-1 最大值:100

最小值:-1

最大值:100

表7 PolicyTriggerResp

参数

参数类型

描述

id

String

调度器id

name

String

调度器名称

properties

PolicyTriggerPropertiesResp object

调度器属性

type

String

调度器类型,目前只支持 time: 定时调度。

表8 PolicyTriggerPropertiesResp

参数

参数类型

描述

pattern

Array of strings

调度规则。限制24条规则。调度器的调度规则,可参照iCalendar RFC 2445规范中的事件规则,但仅支持FREQ、BYDAY、BYHOUR、BYMINUTE、INTERVAL等参数,其中FREQ仅支持WEEKLY和DAILY,BYDAY支持一周七天(MO、TU、WE、TH、FR、SA、SU),BYHOUR支持0-23小时,BYMINUTE支持0-59分钟,并且间隔不能小于一小时,一天最大24个时间点。例如,周一到周天,每天UTC时间的14:00调度,其规则为:'FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYHOUR=14;BYMINUTE=00'。例如:某个地区的时间为 UTC+8,若在该地区每天14:00调度,则在14点基础上减8,其规则为'FREQ=DAILY;INTERVAL=1;BYHOUR=6;BYMINUTE=00'。

start_time

String

调度器开始时间,例如:"2020-01-08 09:59:49"

表9 PolicyAssociateVault

参数

参数类型

描述

destination_vault_id

String

关联的远端存储库ID

vault_id

String

存储库ID

请求示例

查询指定备份策略列表

GET  https://{endpoint}/v3/{project_id}/policies

响应示例

状态码: 200

OK

{
  "policies" : [ {
    "name" : "policy001",
    "associated_vaults" : [ ],
    "enabled" : true,
    "trigger" : {
      "properties" : {
        "pattern" : [ "FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYHOUR=14;BYMINUTE=00" ],
        "start_time" : "2019-05-08T06:57:05.000+00:00"
      },
      "type" : "time",
      "id" : "d67269a6-5369-42d7-8150-5254bd446328",
      "name" : "default"
    },
    "operation_definition" : {
      "retention_duration_days" : 1,
      "year_backups" : 0,
      "day_backups" : 0,
      "month_backups" : 0,
      "week_backups" : 0,
      "timezone" : "UTC+08:00"
    },
    "operation_type" : "backup",
    "id" : "cbb3ce6f-3332-4e7c-b98e-77290d8471ff"
  } ],
  "count" : 10
}

SDK代码示例

SDK代码示例如下。

 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
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.cbr.v1.region.CbrRegion;
import com.huaweicloud.sdk.cbr.v1.*;
import com.huaweicloud.sdk.cbr.v1.model.*;


public class ListPoliciesSolution {

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

        ICredential auth = new BasicCredentials()
                .withAk(ak)
                .withSk(sk);

        CbrClient client = CbrClient.newBuilder()
                .withCredential(auth)
                .withRegion(CbrRegion.valueOf("<YOUR REGION>"))
                .build();
        ListPoliciesRequest request = new ListPoliciesRequest();
        request.withOperationType(ListPoliciesRequest.OperationTypeEnum.fromValue("<operation_type>"));
        request.withVaultId("<vault_id>");
        try {
            ListPoliciesResponse response = client.listPolicies(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());
        }
    }
}
 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
# coding: utf-8

from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcbr.v1.region.cbr_region import CbrRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkcbr.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 = __import__('os').getenv("CLOUD_SDK_AK")
    sk = __import__('os').getenv("CLOUD_SDK_SK")

    credentials = BasicCredentials(ak, sk) \

    client = CbrClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(CbrRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = ListPoliciesRequest()
        request.operation_type = "<operation_type>"
        request.vault_id = "<vault_id>"
        response = client.list_policies(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)
 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
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    cbr "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cbr/v1"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cbr/v1/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cbr/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")

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := cbr.NewCbrClient(
        cbr.CbrClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ListPoliciesRequest{}
	operationTypeRequest:= model.GetListPoliciesRequestOperationTypeEnum().<OPERATION_TYPE>
	request.OperationType = &operationTypeRequest
	vaultIdRequest:= "<vault_id>"
	request.VaultId = &vaultIdRequest
	response, err := client.ListPolicies(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

OK

错误码

请参见错误码

分享:

    相关文档

    相关产品