文档首页> 云备份 CBR> API参考> API> 还原点> 创建备份还原点
更新时间:2024-03-12 GMT+08:00
分享

创建备份还原点

功能介绍

对存储库执行备份,生成备份还原点

调用方法

请参见如何调用API

URI

POST /v3/{project_id}/checkpoints

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

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

表3 请求Body参数

参数

是否必选

参数类型

描述

checkpoint

VaultBackup object

存储库执行备份参数

表4 VaultBackup

参数

是否必选

参数类型

描述

parameters

CheckpointParam object

参数

vault_id

String

存储库ID

表5 CheckpointParam

参数

是否必选

参数类型

描述

auto_trigger

Boolean

是否自动触发,true:自动触发,false:非自动触发。

缺省值:false

description

String

备份描述

最小长度:0

最大长度:255

incremental

Boolean

是否增量备份,true:增量备份,false:非增量备份。

缺省值:true

name

String

备份名称,只能由数字、中文、英文大小写字母,以及下划线"_"和中横线 "-" 字符构成。

最小长度:1

最大长度:64

resources

Array of strings

待备份的资源id列表:uuid

resource_details

Array of Resource objects

资源详情

数组长度:0 - 256

表6 Resource

参数

是否必选

参数类型

描述

extra_info

ResourceExtraInfo object

资源附加信息

id

String

待备份资源id

name

String

待备份资源名称,长度限制:0-255

最小长度:0

最大长度:255

type

String

待备份资源的类型: OS::Nova::Server, OS::Cinder::Volume, OS::Ironic::BareMetalServer, OS::Native::Server, OS::Sfs::Turbo, OS::Workspace::DesktopV2

表7 ResourceExtraInfo

参数

是否必选

参数类型

描述

exclude_volumes

Array of strings

需要排除备份的卷id。仅在多盘备份特性中有效,排除不需要备份的磁盘。当虚拟机新绑定磁盘时,也能继续排除之前设置不用备份的卷。

响应参数

状态码: 200

表8 响应Body参数

参数

参数类型

描述

checkpoint

CheckpointCreate object

还原点信息

表9 CheckpointCreate

参数

参数类型

描述

created_at

String

创建时间,例如:"2020-02-05T10:38:34.209782"

id

String

还原点ID

project_id

String

项目ID

status

String

状态

  • available: 可用

  • deleting: 删除中

  • protecting: 保护中

  • deleted: 已删除

  • error-deleting:删除异常

  • error: 异常

vault

CheckpointPlanCreate object

存储库信息

extra_info

CheckpointExtraInfoResp object

扩展信息

表10 CheckpointPlanCreate

参数

参数类型

描述

id

String

存储库id

name

String

存储库名称

resources

Array of CheckpointResourceResp objects

备份对象

skipped_resources

Array of CheckpointCreateSkippedResource objects

备份时跳过的资源列表

表11 CheckpointResourceResp

参数

参数类型

描述

extra_info

String

资源附加信息

id

String

待备份资源id

name

String

待备份资源名称

protect_status

String

保护状态

  • available: 可用

  • error: 异常

  • protecting: 保护中

  • restoring: 恢复中

  • removing: 删除中

resource_size

String

资源已分配容量,单位为GB

type

String

待备份资源的类型: OS::Nova::Server, OS::Cinder::Volume, OS::Ironic::BareMetalServer, OS::Native::Server, OS::Sfs::Turbo, OS::Workspace::DesktopV2

backup_size

String

副本大小

backup_count

String

副本数量

表12 CheckpointCreateSkippedResource

参数

参数类型

描述

id

String

资源ID

type

String

资源类型

name

String

资源名称

code

String

请参见错误码

reason

String

跳过原因,例如:该资源正在备份中。

表13 CheckpointExtraInfoResp

参数

参数类型

描述

name

String

备份名称

description

String

备份描述

retention_duration

Integer

备份保留天数

请求示例

执行存储库资源自动备份,生成备份还原点。

POST https://{endpoint}/v3/f841e01fd2b14e7fa41b6ae7aa6b0594/checkpoints

{
  "checkpoint" : {
    "parameters" : {
      "auto_trigger" : true,
      "description" : "backup_description",
      "incremental" : true,
      "name" : "backup_name",
      "resources" : [ "94eba8b2-acc9-4d82-badc-127144cc5526" ]
    },
    "vault_id" : "3b5816b5-f29c-4172-9d9a-76c719a659ce"
  }
}

响应示例

状态码: 200

OK

{
  "checkpoint" : {
    "status" : "protecting",
    "created_at" : "2019-05-10T07:59:12.733+00:00",
    "vault" : {
      "skipped_resources" : [ ],
      "id" : "3b5816b5-f29c-4172-9d9a-76c719a659ce",
      "resources" : [ {
        "name" : "ecs-1f0f-0002",
        "resource_size" : 40,
        "protect_status" : "available",
        "type" : "OS::Nova::Server",
        "id" : "94eba8b2-acc9-4d82-badc-127144cc5526"
      } ],
      "name" : "vault-be94"
    },
    "project_id" : "4229d7a45436489f8c3dc2b1d35d4987",
    "id" : "8b0851a8-adf3-4f4c-a914-dead08bf9664",
    "extra_info" : {
      "retention_duration" : -1,
      "name" : "backup_name",
      "description" : "backup_description"
    }
  }
}

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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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.*;

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

public class CreateCheckpointSolution {

    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();
        CreateCheckpointRequest request = new CreateCheckpointRequest();
        VaultBackupReq body = new VaultBackupReq();
        List<String> listParametersResources = new ArrayList<>();
        listParametersResources.add("94eba8b2-acc9-4d82-badc-127144cc5526");
        CheckpointParam parametersCheckpoint = new CheckpointParam();
        parametersCheckpoint.withAutoTrigger(true)
            .withDescription("backup_description")
            .withIncremental(true)
            .withName("backup_name")
            .withResources(listParametersResources);
        VaultBackup checkpointbody = new VaultBackup();
        checkpointbody.withParameters(parametersCheckpoint)
            .withVaultId("3b5816b5-f29c-4172-9d9a-76c719a659ce");
        body.withCheckpoint(checkpointbody);
        request.withBody(body);
        try {
            CreateCheckpointResponse response = client.createCheckpoint(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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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 = CreateCheckpointRequest()
        listResourcesParameters = [
            "94eba8b2-acc9-4d82-badc-127144cc5526"
        ]
        parametersCheckpoint = CheckpointParam(
            auto_trigger=True,
            description="backup_description",
            incremental=True,
            name="backup_name",
            resources=listResourcesParameters
        )
        checkpointbody = VaultBackup(
            parameters=parametersCheckpoint,
            vault_id="3b5816b5-f29c-4172-9d9a-76c719a659ce"
        )
        request.body = VaultBackupReq(
            checkpoint=checkpointbody
        )
        response = client.create_checkpoint(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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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.CreateCheckpointRequest{}
	var listResourcesParameters = []string{
        "94eba8b2-acc9-4d82-badc-127144cc5526",
    }
	autoTriggerParameters:= true
	descriptionParameters:= "backup_description"
	incrementalParameters:= true
	nameParameters:= "backup_name"
	parametersCheckpoint := &model.CheckpointParam{
		AutoTrigger: &autoTriggerParameters,
		Description: &descriptionParameters,
		Incremental: &incrementalParameters,
		Name: &nameParameters,
		Resources: &listResourcesParameters,
	}
	checkpointbody := &model.VaultBackup{
		Parameters: parametersCheckpoint,
		VaultId: "3b5816b5-f29c-4172-9d9a-76c719a659ce",
	}
	request.Body = &model.VaultBackupReq{
		Checkpoint: checkpointbody,
	}
	response, err := client.CreateCheckpoint(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

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

状态码

状态码

描述

200

OK

错误码

请参见错误码

分享:

    相关文档

    相关产品