文档首页/ 云备份 CBR/ API参考(安卡拉区域)/ 应用示例/ 示例2:创建存储库自动备份
更新时间:2024-04-19 GMT+08:00

示例2:创建存储库自动备份

场景描述

本章节指导用户通过策略接口,设置备份策略,绑定策略到存储库实现自动备份。

涉及接口

  • 创建策略:创建执行备份的周期。
  • 设置存储库策略:关联待设置的策略到存储库

操作步骤

  1. 创建策略。
    • 接口相关信息

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

      详情请参见:创建策略 。

    • 请求示例

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

      {endpoint}信息请从管理员处获取。

      Body:

      {
          "policy": {
              "name": "dh_test_policy",
              "trigger": {
                  "properties": {
                      "pattern": ["FREQ=WEEKLY;BYDAY=SU,MO,TU,WE,TH,FR,SA;BYHOUR=23;BYMINUTE=00"]
      }
              },
              "operation_definition": {
                  "retention_duration_days": 30
      }
          }
      }
    • 响应示例
      {
          "policy": {
              "id": "30d7cf2d-14fc-415b-b7da-858b37f47250",
              "name": "dh_test_policy",
              "operation_type": "backup",
              "operation_definition": {
                  "retention_duration_days": 30
              },
              "enabled": true,
              "trigger": {
                  "id": "7954175b-ef2c-432c-b936-f6c83df7a593",
                  "name": "default",
                  "type": "time",
                  "properties": {
                      "pattern": [
                          "FREQ=WEEKLY;BYDAY=SU,MO,TU,WE,TH,FR,SA;BYHOUR=23;BYMINUTE=00"
                      ],
                      "start_time": "2020-08-17 08:39:44"
                  }
              },
              "associated_vaults": null
          }
      }
  2. 设置存储库策略。
    • 接口相关信息

      POST /v3/{project_id}/vaults/{vault_id}/associatepolicy

      详情请参见设置存储库策略。

    • 请求示例

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

      {endpoint}信息请从管理员处获取。

      Body:

      {
          "policy_id": "30d7cf2d-14fc-415b-b7da-858b37f47250"
      }
    • 响应示例
      {
          "associate_policy": {
              "vault_id": "ea7b8717-2543-478a-a92d-3ca7ee448f67",
              "policy_id": "30d7cf2d-14fc-415b-b7da-858b37f47250"
          }
      }