更新时间:2023-11-29 GMT+08:00
分享

示例2:启动迁移任务

场景描述

本章节指导用户通过API启动迁移任务。API的调用方法请参见如何调用API

启动迁移任务前需要获取Token,启动迁移任务后,需要查询任务状态详情,失败或暂停中的任务才能被启动。

涉及接口

操作步骤

  1. 获取IAM用户Token。

    • 接口相关信息

      URI格式:POST /v3/auth/tokens

      详情请参见获取IAM用户Token(使用密码)

    • 请求示例
      POST: https://{iam_endpoint}/v3/auth/tokens

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

      Body:
      {
          "auth": {
              "identity": {
                  "methods": [
                      "password"
                  ],
                  "password": {
                      "user": {
                          "name": "testname",
                          "domain": {
                              "name": "testname"
                          },
                          "password": "Password"
                      }
                  }
              },
              "scope": {
                  "project": {
                      "id": "0215ef11e49d4743be23dd97a1561e91"
                  }
              }
          }
      }

    响应Header中“X-Subject-Token”的值即为Token:

    X-Subject-Token:MIIDkgYJKoZIhvcNAQcCoIIDgzCCA38CAQExDTALBglghkgBZQMEAgEwgXXXXX...

  2. 调用启动任务接口启动迁移任务。

    • 接口相关信息

      URI格式:POST /v2/{project_id}/tasks/{task_id}/start

      详情请参见启动迁移任务

    • 请求示例
      POST: https://{oms_endpoint}/v2/{project_id}/tasks/{task_id}/start

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

      Header:

      Content-Type: application/json
      X-Auth-Token: “Token”

      Body:

      {
              "dst_ak" : "destination_ak",
              "dst_sk" : "destination_sk",
              "src_ak" : "source_ak",
              "src_sk" : "source_sk",
              "migrate_failed_object" : false
      }

      响应200表示调用成功。

  3. 调用查看任务接口,查看任务状态。

    • 接口相关信息

      URI格式:

      GET /v2/{project_id}/tasks/{task_id}

      详情请参见查询指定ID的任务详情

    • 请求示例
      GET: https://{oms_endpoint}/v2/{project_id}/tasks/{task_id}

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

      Header:

      Content-Type: application/json
      X-Auth-Token: “Token”
    • 响应示例
      {
      	"bandwidth_policy" : [],
      	"complete_size" : 2223728,
      	"description" : "",
      	"dst_node" : {
      		"bucket" : "api-test-outline",
      		"region" : "cn-north-7"
      	},
      	"enable_failed_object_recording" : true,
      	"enable_kms" : false,
      	"enable_restore" : false,
      	"error_reason" : null,
      	"failed_num" : 0,
      	"failed_object_record" : {
      		"result" : null,
      		"list_file_key" : null,
      		"error_code" : null
      	},
      	"group_id" : "",
      	"id" : 200477729979132,
      	"is_query_over" : true,
      	"left_time" : 0,
      	"migrate_since" : 0,
      	"migrate_speed" : 71477,
      	"name" : "task_name",
      	"progress" : 1.0,
      	"real_size" : 2223728,
      	"skipped_num" : 0,
      	"src_node" : {
      		"bucket" : "a-test-1",
      		"cloud_type" : "HuaweiCloud",
      		"region" : "cn-north-7",
      		"app_id" : "",
      		"object_key" : ["01.png", "list.txt"],
      		"list_file" : null
      	},
      	"start_time" : 1589267678170,
      	"status" : 5,
      	"successful_num" : 2,
      	"task_type" : "object",
      	"total_num" : 2,
      	"total_size" : 2223728,
      	"total_time" : 31111,
      	"smn_info" : null,
      	"source_cdn" : null
      }                

      status表示任务执行状态,2代表正在执行,5表示执行成功。

相关文档