Updated on 2024-12-30 GMT+08:00

Starting a Migration Task

Scenarios

This section describes how to start a migration task by calling APIs. For details, see Calling APIs.

Before starting a migration task, you need to obtain a token. After starting a migration task, you need to query the task status. You can only start failed or paused tasks.

Involved APIs

Procedure

  1. Obtain the token of the IAM user.

    • API

      URI format: POST /v3/auth/tokens

      For details, see Obtaining a User Token Through Password Authentication.

    • Example request
      POST: https://{iam_endpoint}/v3/auth/tokens

      Obtain {endpoint} from Regions and Endpoints.

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

    In the response header, the value of X-Subject-Token is the token.

    X-Subject-Token:MIIDkgYJKoZIhvcNAQcCoIIDgzCCA38CAQExDTALBglghkgBZQMEAgEwgXXXXX...

  2. Make a call to the API for starting a migration task to start a migration task.

    • API

      URI format: POST /v2/{project_id}/tasks/{task_id}/start

      For details, see Starting a Migration Task.

    • Example request
      POST: https://{oms_endpoint}/v2/{project_id}/tasks/{task_id}/start

      Obtain {endpoint} from Regions and Endpoints.

      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
      }

      If the response code is 200, the API is successfully called.

  3. Make a call to the task viewing API to view the task status.

    • API

      URI format:

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

      For details, see Querying a Migration Task.

    • Example request
      GET: https://{oms_endpoint}/v2/{project_id}/tasks/{task_id}

      Obtain {endpoint} from Regions and Endpoints.

      Header:

      Content-Type: application/json
      X-Auth-Token: "Token"
    • Example response
      {
      	"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 indicates the task execution status. The value 2 indicates that the task is being executed, and the value 5 indicates that the task is successfully executed.