Help Center/ Distributed Cache Service/ API Reference/ API V2/ Data Migration/ Configuring an Online Data Migration Task
Updated on 2026-09-02 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.

Authorization Information

Each account has all the permissions required to call all APIs, but IAM users must be assigned the required permissions.

  • If you are using role/policy-based authorization, see Permissions Policies and Supported Actions for details on the required permissions.
  • If you are using identity policy-based authorization, the following identity policy-based permissions are required.

    Action

    Access Level

    Resource Type (*: required)

    Condition Key

    Alias

    Dependencies

    dcs:migrationTask:modify

    Write

    migrationTask *

    -

    • dcs:migrationTask:exchangeIp
    • dcs:migrationTask:rollbackIp

    -

URI

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

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Definition

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

Constraints

N/A

Range

N/A

Default Value

N/A

task_id

Yes

String

Definition

Online migration task ID.

Constraints

The ID must be that of an existing online migration task.

Range

N/A

Default Value

N/A

Request Parameters

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

migration_method

Yes

String

Definition

Type of the migration, which can be full migration or incremental migration.

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

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

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

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

Constraints

This parameter is mandatory. If the value is invalid, the error message INVALID_REQUEST_PARAM is returned.

Range

  • full_amount_migration: full migration

  • incremental_migration: incremental migration

Default Value

N/A

resume_mode

Yes

String

Definition

Reconnection mode.

If the source and target instances are disconnected due to network exceptions, automatic reconnections will be performed indefinitely.

If incremental synchronization fails, full synchronization will be triggered, increasing bandwidth usage. Exercise caution when enabling this option.

Constraints

This parameter is available only for V2 data migration APIs. If an invalid value is used, the error message QUERY_PARAM_INVALID is returned.

Range

  • auto: automatic reconnection.

  • manual: manual reconnection.

Default Value

manual

bandwidth_limit_mb

No

String

Definition

Migration bandwidth limit, in MB/s. If this parameter is not specified, the bandwidth is not limited.

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.

Constraints

The value must be a positive integer and cannot exceed the maximum value.

Range

1–10240

Default Value

N/A

source_instance

Yes

ConfigMigrationInstanceBody object

Definition

Source Redis information.

Constraints

  • Either id or addrs must be specified.

  • The source and target instances cannot be the same.

  • The source instance cannot be an instance with eventlog enabled.

Range

N/A

Default Value

N/A

target_instance

Yes

ConfigMigrationInstanceBody object

Definition

Target Redis information.

Constraints

Either id or addrs must be specified.

Range

N/A

Default Value

N/A

Table 3 ConfigMigrationInstanceBody

Parameter

Mandatory

Type

Description

id

No

String

Definition

Redis instance ID. This parameter is mandatory for a Redis instance in the cloud.

Constraints

Either this parameter or addrs must be set.

Range

N/A

Default Value

N/A

addrs

No

String

Definition

Address of a Redis instance. This parameter is mandatory for a self-hosted Redis instance.

Constraints

Either this parameter or id must be set.

Range

N/A

Default Value

N/A

password

No

String

Definition

Redis connection password.

Constraints

If a password is set, this parameter is mandatory.

Range

N/A

Default Value

N/A

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

id

String

Definition

Migration task ID.

Range

N/A

name

String

Definition

Migration task name.

Range

N/A

status

String

Definition

Migration task status. The value can be SUCCESS, FAILED, MIGRATING, or TERMINATED.

Range

  • FULLMIGRATING: Full migration is in progress.

  • SUCCESS: The migration is successful.

  • FAILED: The migration failed.

  • MIGRATING: The migration is in progress.

  • TERMINATED: The migration has been terminated.

error

String

Definition

Error information.

Range

N/A

Status code: 400

Table 5 Response body parameters

Parameter

Type

Description

error_msg

String

Definition

Error information.

Range

N/A

error_code

String

Definition

Error code.

Range

For details, see Error Codes.

error_ext_msg

String

Definition

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

Range

N/A

Status code: 401

Table 6 Response body parameters

Parameter

Type

Description

error_msg

String

Definition

Error information.

Range

N/A

error_code

String

Definition

Error code.

Range

For details, see Error Codes.

error_ext_msg

String

Definition

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

Range

N/A

Status code: 403

Table 7 Response body parameters

Parameter

Type

Description

error_msg

String

Definition

Error information.

Range

N/A

error_code

String

Definition

Error code.

Range

For details, see Error Codes.

error_ext_msg

String

Definition

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

Range

N/A

Status code: 404

Table 8 Response body parameters

Parameter

Type

Description

error_msg

String

Definition

Error information.

Range

N/A

error_code

String

Definition

Error code.

Range

For details, see Error Codes.

error_ext_msg

String

Definition

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

Range

N/A

Status code: 500

Table 9 Response body parameters

Parameter

Type

Description

error_msg

String

Definition

Error information.

Range

N/A

error_code

String

Definition

Error code.

Range

For details, see Error Codes.

error_ext_msg

String

Definition

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

Range

N/A

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" : null
}

SDK Sample Code

The SDK sample code is as follows.

Java

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.SetOnlineMigrationTaskBody.fromValue("auto"));
        body.withMigrationMethod(SetOnlineMigrationTaskBody.SetOnlineMigrationTaskBody.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());
        }
    }
}

Python

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)

Go

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
61
62
63
64
65
66
67
68
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, err := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        SafeBuild()

    if err != nil {
        fmt.Println(err)
        return
    }

    hcClient, err := dcs.DcsClientBuilder().
         WithRegion(region.ValueOf("<YOUR REGION>")).
         WithCredential(auth).
         SafeBuild()


    if err != nil {
        fmt.Println(err)
        return
    }

    client := dcs.NewDcsClient(hcClient)

    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)
    }
}

More

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.