Help Center/ Distributed Cache Service/ API Reference/ API V2/ Data Migration/ Configuring an Online Data Migration Task
Updated on 2024-11-06 GMT+08:00

Configuring an Online Data Migration Task

Function

This API is used to configure an online data migration task.

Calling Method

For details, see Calling APIs.

URI

POST /v2/{project_id}/migration/{task_id}/task

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details, see Obtaining a Project ID.

task_id

Yes

String

Online migration task ID.

Request Parameters

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

migration_method

Yes

String

Type of the migration.

  • Full migration is suitable for scenarios where services can be interrupted. Data is migrated at one time.

    Source instance data updated during the migration will not be migrated to the target instance.

  • Incremental migration is suitable for scenarios requiring minimal service downtime.

    The incremental migration parses logs to ensure data consistency between the source and target instances.

    After the full migration is complete, incremental migration starts.Options:

  • full_amount_migration: full migration

  • incremental_migration: incremental migration

resume_mode

Yes

String

Reconnection mode.

In automatic reconnection mode, if the source and target instances are disconnected due to network exceptions, automatic reconnections will be performed indefinitely.

Full synchronization will be triggered and requires more bandwidth if incremental synchronization becomes unavailable. Exercise caution when enabling this option.

Values:

  • auto: automatically reconnect.

  • manual: manually reconnect.

bandwidth_limit_mb

No

String

Bandwidth limit. For incremental migration, you can limit the bandwidth to ensure smooth service running. When the data synchronization speed reaches the limit, it can no longer increase. - Unit: MB/s. - Value range: 1–10,240 (an integer greater than 0 and less than 10,241).

source_instance

Yes

ConfigMigrationInstanceBody object

Source Redis information.

target_instance

Yes

ConfigMigrationInstanceBody object

Target Redis information.

Table 3 ConfigMigrationInstanceBody

Parameter

Mandatory

Type

Description

id

No

String

Redis instance ID (mandatory if the source Redis address is not specified).

addrs

No

String

Source Redis address (mandatory if the Redis instance ID is not specified).

password

No

String

Redis password. If a password is set, this parameter is mandatory.

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

id

String

Migration task ID.

name

String

Migration task name.

status

String

Migration status. Options: SUCCESS, FAILED, MIGRATING, TERMINATED.

error

String

Error message.

Status code: 400

Table 5 Response body parameters

Parameter

Type

Description

error_msg

String

Error message.

error_code

String

Error code.

error_ext_msg

String

Extended error information. This parameter is not used currently and is set to null.

Status code: 401

Table 6 Response body parameters

Parameter

Type

Description

error_msg

String

Error message.

error_code

String

Error code.

error_ext_msg

String

Extended error information. This parameter is not used currently and is set to null.

Status code: 403

Table 7 Response body parameters

Parameter

Type

Description

error_msg

String

Error message.

error_code

String

Error code.

error_ext_msg

String

Extended error information. This parameter is not used currently and is set to null.

Status code: 404

Table 8 Response body parameters

Parameter

Type

Description

error_msg

String

Error message.

error_code

String

Error code.

error_ext_msg

String

Extended error information. This parameter is not used currently and is set to null.

Status code: 500

Table 9 Response body parameters

Parameter

Type

Description

error_msg

String

Error message.

error_code

String

Error code.

error_ext_msg

String

Extended error information. This parameter is not used currently and is set to null.

Example Requests

Configuring an online migration task with migration type set to incremental, auto-reconnect enabled, and source and target instances configured

POST https://{dcs_endpoint}/v2/{project_id}/migration/{task_id}/task

{
  "migration_method" : "incremental_migration",
  "bandwidth_limit_mb" : 123,
  "resume_mode" : "auto",
  "source_instance" : {
    "id" : null,
    "addrs" : "192.168.1.1:6379,192.168.0.0:6379",
    "password" : "xxxxxx"
  },
  "target_instance" : {
    "id" : "cf4a05df-1c38-47c5-bb5a-0a7b3673b3bd",
    "addrs" : null,
    "password" : null
  }
}

Example Responses

Status code: 200

Online data migration task configured.

{
  "id" : "90754308-a156-406f-a837-8f852f38a646",
  "name" : "dcs-migration-1db7",
  "status" : "FULLMIGRATING",
  "error" : ""
}

SDK Sample Code

The SDK sample code is as follows.

Configuring an online migration task with migration type set to incremental, auto-reconnect enabled, and source and target instances configured

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.dcs.v2.region.DcsRegion;
import com.huaweicloud.sdk.dcs.v2.*;
import com.huaweicloud.sdk.dcs.v2.model.*;


public class SetOnlineMigrationTaskSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");
        String projectId = "{project_id}";

        ICredential auth = new BasicCredentials()
                .withProjectId(projectId)
                .withAk(ak)
                .withSk(sk);

        DcsClient client = DcsClient.newBuilder()
                .withCredential(auth)
                .withRegion(DcsRegion.valueOf("<YOUR REGION>"))
                .build();
        SetOnlineMigrationTaskRequest request = new SetOnlineMigrationTaskRequest();
        request.withTaskId("{task_id}");
        SetOnlineMigrationTaskBody body = new SetOnlineMigrationTaskBody();
        ConfigMigrationInstanceBody targetInstancebody = new ConfigMigrationInstanceBody();
        targetInstancebody.withId("cf4a05df-1c38-47c5-bb5a-0a7b3673b3bd");
        ConfigMigrationInstanceBody sourceInstancebody = new ConfigMigrationInstanceBody();
        sourceInstancebody.withAddrs("192.168.1.1:6379,192.168.0.0:6379")
            .withPassword("xxxxxx");
        body.withTargetInstance(targetInstancebody);
        body.withSourceInstance(sourceInstancebody);
        body.withBandwidthLimitMb("123");
        body.withResumeMode(SetOnlineMigrationTaskBody.ResumeModeEnum.fromValue("auto"));
        body.withMigrationMethod(SetOnlineMigrationTaskBody.MigrationMethodEnum.fromValue("incremental_migration"));
        request.withBody(body);
        try {
            SetOnlineMigrationTaskResponse response = client.setOnlineMigrationTask(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}

Configuring an online migration task with migration type set to incremental, auto-reconnect enabled, and source and target instances configured

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkdcs.v2.region.dcs_region import DcsRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkdcs.v2 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]
    projectId = "{project_id}"

    credentials = BasicCredentials(ak, sk, projectId)

    client = DcsClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(DcsRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = SetOnlineMigrationTaskRequest()
        request.task_id = "{task_id}"
        targetInstancebody = ConfigMigrationInstanceBody(
            id="cf4a05df-1c38-47c5-bb5a-0a7b3673b3bd"
        )
        sourceInstancebody = ConfigMigrationInstanceBody(
            addrs="192.168.1.1:6379,192.168.0.0:6379",
            password="xxxxxx"
        )
        request.body = SetOnlineMigrationTaskBody(
            target_instance=targetInstancebody,
            source_instance=sourceInstancebody,
            bandwidth_limit_mb="123",
            resume_mode="auto",
            migration_method="incremental_migration"
        )
        response = client.set_online_migration_task(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Configuring an online migration task with migration type set to incremental, auto-reconnect enabled, and source and target instances configured

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    dcs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")
    projectId := "{project_id}"

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        Build()

    client := dcs.NewDcsClient(
        dcs.DcsClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.SetOnlineMigrationTaskRequest{}
	request.TaskId = "{task_id}"
	idTargetInstance:= "cf4a05df-1c38-47c5-bb5a-0a7b3673b3bd"
	targetInstancebody := &model.ConfigMigrationInstanceBody{
		Id: &idTargetInstance,
	}
	addrsSourceInstance:= "192.168.1.1:6379,192.168.0.0:6379"
	passwordSourceInstance:= "xxxxxx"
	sourceInstancebody := &model.ConfigMigrationInstanceBody{
		Addrs: &addrsSourceInstance,
		Password: &passwordSourceInstance,
	}
	bandwidthLimitMbSetOnlineMigrationTaskBody:= "123"
	request.Body = &model.SetOnlineMigrationTaskBody{
		TargetInstance: targetInstancebody,
		SourceInstance: sourceInstancebody,
		BandwidthLimitMb: &bandwidthLimitMbSetOnlineMigrationTaskBody,
		ResumeMode: model.GetSetOnlineMigrationTaskBodyResumeModeEnum().AUTO,
		MigrationMethod: model.GetSetOnlineMigrationTaskBodyMigrationMethodEnum().INCREMENTAL_MIGRATION,
	}
	response, err := client.SetOnlineMigrationTask(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.

Status Codes

Status Code

Description

200

Online data migration task configured.

400

Invalid request.

401

Invalid authentication information.

403

The request is rejected.

404

The requested resource is not found.

500

Internal service error.

Error Codes

See Error Codes.