文档首页/ 云备份 CBR/ API参考(吉隆坡区域)/ 应用示例/ 示例1:创建弹性云服务器备份
更新时间:2022-08-16 GMT+08:00

示例1:创建弹性云服务器备份

场景描述

章节指导用户通过API创建云服务器备份。API的调用方法请参见如何调用API

创建备份时,支持云服务器或磁盘等资源备份。本节我们以云服务器为例,介绍如何创建云服务器备份。

涉及接口

创建云服务器备份时,需要进行创建备份的容器存储库,将服务器或磁盘等资源挂载至存储库,为服务器或磁盘等资源创建备份。涉及的接口如下:

  • 创建存储库:创建备份的容器。
  • 为存储库添加保护资源:确定待备份云服务器或磁盘。
  • 创建备份还原点:创建备份。
  • 查询备份还原点:确认备份创建成功。

操作步骤

  1. 创建存储库。
    1. 创建简单配置的存储库。
      • 接口相关信息

        URI格式:POST /v3/{project_id}/vaults

        详情请参见创建存储库。

      • 请求示例

        POST: https://{endpoint}/v3/{project_id}/vaults

        {endpoint}信息请从地区和终端节点获取。

        Body:

        {
            "vault": {
                   "billing": {
                          "cloud_type": "public",
                          "consistent_level": "crash_consistent",
                          "object_type": "server",
                          "protect_type": "backup",
                          "size": 200
                   },
                   "name": "my_vault",
                   "resources": []
            }
        }
      • 响应示例
        {
            "vault": {
                "id": "ea7b8717-2543-478a-a92d-3ca7ee448f67",
                "name": "my_vault",
                "description": null,
                "resources": [],
                "provider_id": "0daac4c5-6707-4851-97ba-169e36266b66",
                "created_at": "2020-08-17T03:51:24.678916",
                "project_id": "0605767b5780d5762fc5c0118072a564",
                "enterprise_project_id": "0",
                "auto_bind": false,
                "bind_rules": {},
                "user_id": "aa2999fa5ae640f28926f8fd79188934",
                "billing": {
                    "allocated": 0,
                    "cloud_type": "public",
                    "consistent_level": "crash_consistent",
                    "frozen_scene": null,
                    "charging_mode": "post_paid",
                    "order_id": null,
                    "product_id": null,
                    "protect_type": "backup",
                    "object_type": "server",
                    "spec_code": "vault.backup.server.normal",
                    "used": 0,
                    "storage_unit": null,
                    "status": "available",
                    "size": 200
                },
                "tags": []
            }
        }
  2. 为存储库添加保护资源,将服务器/磁盘绑定到存储库中。
    1. 添加资源
      • 接口相关信息

        URI格式:POST /v3/{project_id}/vaults/{vault_id}/addresources

        详情请参见添加资源。

      • 请求示例

        POST: https://{endpoint}/v3/0605767b5780d5762fc5c0118072a564 /vaults/ea7b8717-2543-478a-a92d-3ca7ee448f67/addresources

        {endpoint}信息请从地区和终端节点获取。

        Body:

        {
            "resources": [{
                   "id": "e8cc6bfd-d324-4b88-9109-9fb0ba70676f",
                   "type": "OS::Nova::Server",
                   "name": "server-4690-0002" 
            }]
        }
      • 响应示例
        {
            "add_resource_ids": [
                "e8cc6bfd-d324-4b88-9109-9fb0ba70676f"
            ]
        }
    2. 请求体中根据需要选择运行中且没有绑定存储库的云服务器ID。
  3. 创建备份还原点。
    1. 创建备份还原点。
      • 接口相关信息

        URI格式:POST /v3/{project_id}/checkpoints

        详情请参见创建备份还原点。

      • 请求示例

        POST: https://{endpoint}/v3/0605767b5780d5762fc5c0118072a564/checkpoints

        {endpoint}信息请从地区和终端节点获取。

        Body:

        {
            "checkpoint": {
                "parameters": {
                    "auto_trigger": false,
                    "description": "backupauto",
                    "incremental": true,
                    "name": "backup_auto",
                    "resources": ["e8cc6bfd-d324-4b88-9109-9fb0ba70676f"]
                  },
                "vault_id": "ea7b8717-2543-478a-a92d-3ca7ee448f67"
            }
        }
      • 响应示例
        {
            "checkpoint": {
                "id": "d9ce6924-d753-4132-bd16-a9f8838ea7d2",
                "project_id": "0605767b5780d5762fc5c0118072a564",
                "status": "protecting",
                "vault": {
                    "id": "ea7b8717-2543-478a-a92d-3ca7ee448f67",
                    "name": "my_vault",
                    "resources": [
                        {
                            "id": "e8cc6bfd-d324-4b88-9109-9fb0ba70676f",
                            "type": "OS::Nova::Server",
                            "name": "ecs-9f93-0002",
                            "extra_info": "{}",
                            "resource_size": "40",
                            "backup_size": "0",
                            "backup_count": "0",
                            "protect_status": "available"
                        }
                    ],
                    "skipped_resources": []
                },
                "created_at": "2020-08-17T06:49:06.307378",
                "extra_info": {
                    "name": "backup_auto",
                    "description": "backupauto",
                    "retention_duration": -1
                }
            }
        }
    2. 记录响应消息体中备份还原点ID。
  4. 确认服务器备份成功。
    • 接口相关信息

      URI格式:GET /v3/{project_id}/checkpoints/{checkpoint_id}

      详情请参见查询备份还原点

      {endpoint}信息请从地区和终端节点获取。

    • 请求示例

      GET: https://{endpoint}/v3/0605767b5780d5762fc5c0118072a564/checkpoints/d9ce6924-d753-4132-bd16-a9f8838ea7d2

    • 响应示例
      {
          "checkpoint": {
              "id": "d9ce6924-d753-4132-bd16-a9f8838ea7d2",
              "project_id": "0605767b5780d5762fc5c0118072a564",
              "status": "available",
              "vault": null,
              "created_at": "2020-08-17T06:49:06.260790",
              "extra_info": null
          }
      }