文档首页 > > API参考> 应用示例> 示例1:创建弹性云服务器备份

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

分享
更新时间:2020/09/01 GMT+08:00

场景描述

章节指导用户通过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. 创建包周期存储库并直接绑定服务器。
      • 接口相关信息

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

        接口与步骤a保持一致。

      • 请求示例

        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": 100,
                          "charging_mode": "pre_paid",
                          "period_type": "month",
                          "period_num": 1,
                          "is_auto_renew": false,
                          "is_auto_pay": false
                   },
                   "description": "vault_description",
                   "name": "vault_name",
                   "resources": [{
                          "id": "97595625-198e-4e4d-879b-9d53f68ba551",
                          "type": "OS::Nova::Server"
                   }]
            }
        }
    3. 记录响应消息体中存储库ID
  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
          }
      }
分享:

    相关文档

    相关产品

文档是否有解决您的问题?

提交成功!非常感谢您的反馈,我们会继续努力做到更好!
反馈提交失败,请稍后再试!

*必选

请至少选择或填写一项反馈信息

字符长度不能超过200

提交反馈 取消

如您有其它疑问,您也可以通过华为云社区问答频道来与我们联系探讨

智能客服提问云社区提问