Help Center> Distributed Cache Service> API Reference> Examples> Example 2: Creating a Data Migration Task
Updated on 2024-03-05 GMT+08:00

Example 2: Creating a Data Migration Task

Scenario

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

An online full migration task is used as an example. The source and destination of the migration are DCS Redis instances in the same VPC on HUAWEI CLOUD.

Involved APIs

Call APIs to perform the following steps required to create a data migration task:

Step 1: Determine the Source IP Address and Port Number

  1. Query the IP address and port number of a specific instance.

    • URI

      URI format: GET /v2/{project_id}/instances/{instance_id}

    • Example request

      GET https://{dcs_endpoint}/v2/666486c2d9b948c1bbea57e714d744fa/instances/21bc7b53-2494-4f10-bb0b-c0b913d9e329

      To obtain the value of {dcs_endpoint}, see Regions and Endpoints.

    • Example response
      {
      	"free": null,
      	"max_memory": 2048,
      	"used_memory": 1,
      	"instance_id": "21bc7b53-2494-4f10-bb0b-c0b913d9e329",
      	"name": "dcs-api-test",
      	"resource_spec_code": "redis.single.au1.large.2",
      	"engine": "Redis",
      	"engine_version": "5.0",
      	"internal_version": null,
      	"charging_mode": 0,
      	"capacity": 2,
      	"capacity_minor": null,
      	"vpc_id": "743bf021-2c2d-4511-aeac-85bd48c06af7",
      	"vpc_name": "vpc-d2d4",
      	"ip": "192.168.0.100",
      	"domain_name": "redis-88a7bbb-dcs-api-test.dcs.huaweicloud.com",
      	"readonly_domain_name": null,
      	"port": 6379,
      	"status": "RUNNING",
      	"freeze_scene": null,
      	"created_at": "2020-06-05T03:30:36.273Z",
      	"update_at": "2020-06-05T03:30:47.231Z",
      	"error_code": null,
      	"user_id": "d53977d1adfb49c5b025ba7d33a13fd7",
      	"user_name": "paas_dcs_a00421997_02",
      	"maintain_begin": "02:00:00",
      	"maintain_end": "06:00:00",
      	"no_password_access": "true",
      	"access_user": null,
      	"enable_publicip": false,
      	"publicip_id": null,
      	"publicip_address": null,
      	"enable_ssl": false,
      	"service_upgrade": false,
      	"service_task_id": "",
      	"enterprise_project_id": "0",
      	"security_group_id": null,
      	"tags": [],
      	"product_type": "generic",
      	"cpu_type": "aarch64",
      	"storage_type": "DRAM",
      	"launched_at": "2020-06-05T03:30:47.238Z",
      	"is_free": null,
      	"libos": false,
      	"cache_mode": "single",
      	"available_zones": ["d539378ec1314c85b76fefa3f7071458"],
      	"subnet_id": "a4112635-3ec0-471c-95c3-5cf49b9533af",
      	"backend_addrs": null,
      	"crr_role": null,
      	"cloud_service_type_code": "hws.service.type.dcs",
      	"cloud_resource_type_code": "hws.resource.type.dcs3",
      	"support_slow_log_flag": null,
      	"ipv6": null,
      	"enable_ipv6": false,
      	"description": "",
      	"product_id": "redis.single.au1.large.2-h",
      	"security_group_name": null,
      	"subnet_name": "dcs-beta",
      	"order_id": null,
      	"subnet_cidr": "192.168.0.0/24",
      	"task": null,
      	"instance_backup_policy": null,
      	"enterprise_project_name": null
      }

  2. Record the required IP address and port number of the instance.

Step 2: Create a Data Migration Task

  • URI

    URI format: POST /v2/{project_id}/migration-task

  • Example request

    POST https://{dcs_endpoint}/v2/666486c2d9b948c1bbea57e714d744fa/migration-task

    To obtain the value of {dcs_endpoint}, see Regions and Endpoints.

    Body:

    {
    	"migration_method": "full_amount_migration",
    	"migration_type": "online_migration",
    	"network_type": "vpc",
    	"source_instance": {
    		"addrs": "192.168.0.79:6379"
    	},
    	"target_instance": {
    		"id": "92b2b922-0f96-4664-acc5-04d922867c4d"
    	},
    	"task_name": "dcs-test-migration"
    }
  • Example response
    {
    	"id": "8aa6999f727f0a40017283479d730d7c",
    	"name": "dcs-test-migration",
    	"status": "MIGRATING",
    	"error": ""
    }

    For details about the parameters for creating a data migration task, see Creating a Backup Import Task.

Step 3: Query the Migration Result

  • URI

    URI format: GET /v2/{project_id}/migration-task/{task_id}

  • Example request

    GET https://{dcs_endpoint}/v2/666486c2d9b948c1bbea57e714d744fa/migration-task/8aa6999f727f0a40017283479d730d7c

    To obtain the value of {dcs_endpoint}, see Regions and Endpoints.

  • Example response
    {
    	"task_name": "dcs-test-migration",
    	"task_id": "8aa6999f727f0a40017283479d730d7c",
    	"description": null,
    	"status": "SUCCESS",
    	"migration_type": "online_migration",
    	"migration_method": "full_amount_migration",
    	"backup_files": null,
    	"network_type": "vpc",
    	"bandwidth_limit_mb": null,
    	"source_instance": {
    		"id": null,
    		"ip": "192.168.0.79:6379",
    		"port": null,
    		"name": null,
    		"password": null,
    		"addrs": null
    	},
    	"target_instance": {
    		"id": "92b2b922-0f96-4664-acc5-04d922867c4d",
    		"ip": null,
    		"port": null,
    		"name": "dcs-xwvq",
    		"password": null,
    		"addrs": null
    	},
    	"created_at": "2020-06-05T07:00:08.204Z",
    	"updated_at": "2020-06-05T07:03:25.075Z"
    }

    If the task status is SUCCESS, the migration is successful.