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

Creating a Migration Task

Scenarios

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

Supported migration task types include URL list migration, object name prefix migration, object list migration, and file/folder migration. This section describes how to create a file/folder migration task.

Involved APIs

Prerequisites

  • You have obtained the AK/SK pair of the source platform account.
  • You have obtained AK/SK of the destination platform account. For details about how to obtain AKs and SKs, see Creating Access Keys (AK and SK).
  • You have obtained the endpoints of IAM and OMS. For details, see Regions and Endpoints.
  • You have obtained the region where the source bucket locates.
  • The destination bucket has been created. For details, see Creating a Bucket.
  • You have obtained the region where the destination bucket locates. For details, see Viewing Bucket Information.
  • You have obtained the project ID. For details, see Obtaining a Project ID.

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": "username",
                          "domain": {
                              "name": "domainname"
                          },
                          "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 creating a migration task to create a migration task.

    • API

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

      For details, see Creating a Migration Task.

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

      Obtain {endpoint} from Regions and Endpoints.

      Header:

      Content-Type: application/json
      X-Auth-Token: "Token"

      Body:

      {
      	"src_node" : {
      		"region" : "source_bucket_region",
      		"ak" : "source_ak",
      	"sk" : "source_sk",
      		"bucket" : "source_bucket",
      		"cloud_type" : "cloud_type",
      		"object_key" : ["01.png", "list.txt"]
      	},
      	"enable_kms" : false,
      	"description" : "",
      	"dst_node" : {
      		"region" : "destination_bucket_region",
      		"ak" : "destination_ak",
      		"sk" : "destination_sk",
      		"bucket" : "destination_bucket"
      	},
      	"enable_failed_object_recording" : true,
      	"enable_restore" : false,
      	"task_type" : "object"
      }
    • Example response
      {
              "id" : 200477729979132,
              "task_name" : "task_name"
      }

  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 5 indicates that the task is successfully executed.