Help Center/ Object Storage Migration Service/ API Reference/ Application Examples/ Example 3: Pausing and Deleting a Migration Task
Updated on 2024-12-30 GMT+08:00

Example 3: Pausing and Deleting a Migration Task

Scenarios

This section describes how to pause and delete a migration task using an API. For details, see Calling APIs.

Before deleting a migration task, you need to obtain the token. After pausing the migration task, you need to query the task status. The migration task can be deleted only after it is paused.

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 pausing a migration task to pause a migration task.

    • API

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

      For details, see Pausing a Migration Task.

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

      Obtain {endpoint} from Regions and Endpoints.

      Header:

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

      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" : 3,
      	"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 3 indicates that the task is paused.

  4. Make a call to the API for deleting a migration task to delete a migration task.

    • API

      URI format: DELETE /v2/{project_id}/tasks/{task_id}

      For details, see Deleting a Migration Task.

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

      Obtain {endpoint} from Regions and Endpoints.

      Header:

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

      If the response code is 200, the migration task is deleted successfully.