Updated on 2024-11-06 GMT+08:00

Creating a Backup Import Task

Function

This API is used to create a backup import task.

Calling Method

For details, see Calling APIs.

URI

POST /v2/{project_id}/migration-task

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

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

Request Parameters

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

task_name

Yes

String

Backup import task name.

description

No

String

Backup import task description.

migration_type

Yes

String

Migration mode.

Options:

  • backupfile_import: importing backup files

  • online_migration: migrating data online This API can no longer be used to create an online migration task. Please call CreateOnlineMigrationTask instead.

migration_method

Yes

String

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

Values:

  • full_amount_migration: full migration

  • incremental_migration: incremental migration

backup_files

No

BackupFilesBody object

Backup files to be imported when the migration mode is backup file import.

network_type

No

String

Type of the network for communication between the source and target Redis when the migration mode is online data migration. This API can no longer be used to create an online migration task. Please call CreateOnlineMigrationTask instead.

source_instance

No

SourceInstanceBody object

Source Redis information. This parameter is mandatory when the migration mode is online data migration. This API can no longer be used to create an online migration task. Please call CreateOnlineMigrationTask instead.

target_instance

Yes

TargetInstanceBody object

Target Redis information.

Table 3 BackupFilesBody

Parameter

Mandatory

Type

Description

file_source

No

String

Data source, which can be an OBS bucket or a backup record.

bucket_name

No

String

Name of the OBS bucket.

files

Yes

Array of Files objects

List of backup files to be imported. This parameter is mandatory when the data source is an OBS bucket.

backup_id

No

String

Backup record ID. This parameter is mandatory when the data source is a backup record.

Table 4 Files

Parameter

Mandatory

Type

Description

file_name

Yes

String

Name of a backup file.

size

No

String

File size in bytes.

update_at

No

String

Time when the file was last modified. The format is YYYY-MM-DD HH:MM:SS.

Table 5 SourceInstanceBody

Parameter

Mandatory

Type

Description

addrs

Yes

String

Source Redis address (specified in the source_instance parameter).

password

No

String

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

task_status

No

String

Task status.

id

No

String

Redis instance ID.

ip

No

String

Redis IP address.

port

No

String

Redis port.

name

No

String

Redis name.

proxy_multi_db

No

Boolean

Indicates whether multi-DB is enabled for Proxy Cluster DCS instances.

db

No

String

Redis database.

Table 6 TargetInstanceBody

Parameter

Mandatory

Type

Description

id

Yes

String

Redis instance ID (mandatory in the target_instance parameter).

name

No

String

Redis instance name (specified in the target_instance parameter).

password

No

String

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

task_status

No

String

Task status.

ip

No

String

Redis IP address.

port

No

String

Redis port.

addrs

No

String

Redis instance address.

proxy_multi_db

No

Boolean

Indicates whether multi-DB is enabled for Proxy Cluster DCS instances.

db

No

String

Redis database.

Response Parameters

Status code: 200

Table 7 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 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: 401

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.

Status code: 403

Table 10 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 11 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 12 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

Creating a backup import task to migrate data from an OBS bucket

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

{
  "task_name" : "migration1",
  "description" : "Test",
  "migration_type" : "backupfile_import",
  "migration_method" : "full_amount_migration",
  "backup_files" : {
    "bucket_name" : "bucketName",
    "file_source" : "self_build_obs",
    "files" : [ {
      "size" : "754.0MB",
      "file_name" : "fileName"
    } ]
  },
  "target_instance" : {
    "id" : "d2c8399f-bdba-43c1-8069-3ff17a1a79d5",
    "name" : "dcs-test",
    "password" : "xxxxxx"
  }
}

Example Responses

Status code: 200

Backup import task created.

{
  "id" : "8aa6999e71cb638b0171f485f5266ef0",
  "name" : "dcs-test",
  "status" : "MIGRATING",
  "error" : ""
}

SDK Sample Code

The SDK sample code is as follows.

Creating a backup import task to migrate data from an OBS bucket

 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
69
70
71
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.*;

import java.util.List;
import java.util.ArrayList;

public class CreateMigrationTaskSolution {

    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();
        CreateMigrationTaskRequest request = new CreateMigrationTaskRequest();
        CreateMigrationTaskBody body = new CreateMigrationTaskBody();
        TargetInstanceBody targetInstancebody = new TargetInstanceBody();
        targetInstancebody.withId("d2c8399f-bdba-43c1-8069-3ff17a1a79d5")
            .withName("dcs-test")
            .withPassword("xxxxxx");
        List<Files> listBackupFilesFiles = new ArrayList<>();
        listBackupFilesFiles.add(
            new Files()
                .withFileName("fileName")
                .withSize("754.0MB")
        );
        BackupFilesBody backupFilesbody = new BackupFilesBody();
        backupFilesbody.withFileSource(BackupFilesBody.FileSourceEnum.fromValue("self_build_obs"))
            .withBucketName("bucketName")
            .withFiles(listBackupFilesFiles);
        body.withTargetInstance(targetInstancebody);
        body.withBackupFiles(backupFilesbody);
        body.withMigrationMethod(CreateMigrationTaskBody.MigrationMethodEnum.fromValue("full_amount_migration"));
        body.withMigrationType(CreateMigrationTaskBody.MigrationTypeEnum.fromValue("backupfile_import"));
        body.withDescription("Test");
        body.withTaskName("migration1");
        request.withBody(body);
        try {
            CreateMigrationTaskResponse response = client.createMigrationTask(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());
        }
    }
}

Creating a backup import task to migrate data from an OBS bucket

 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
# 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 = CreateMigrationTaskRequest()
        targetInstancebody = TargetInstanceBody(
            id="d2c8399f-bdba-43c1-8069-3ff17a1a79d5",
            name="dcs-test",
            password="xxxxxx"
        )
        listFilesBackupFiles = [
            Files(
                file_name="fileName",
                size="754.0MB"
            )
        ]
        backupFilesbody = BackupFilesBody(
            file_source="self_build_obs",
            bucket_name="bucketName",
            files=listFilesBackupFiles
        )
        request.body = CreateMigrationTaskBody(
            target_instance=targetInstancebody,
            backup_files=backupFilesbody,
            migration_method="full_amount_migration",
            migration_type="backupfile_import",
            description="Test",
            task_name="migration1"
        )
        response = client.create_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)

Creating a backup import task to migrate data from an OBS bucket

 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
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.CreateMigrationTaskRequest{}
	nameTargetInstance:= "dcs-test"
	passwordTargetInstance:= "xxxxxx"
	targetInstancebody := &model.TargetInstanceBody{
		Id: "d2c8399f-bdba-43c1-8069-3ff17a1a79d5",
		Name: &nameTargetInstance,
		Password: &passwordTargetInstance,
	}
	sizeFiles:= "754.0MB"
	var listFilesBackupFiles = []model.Files{
        {
            FileName: "fileName",
            Size: &sizeFiles,
        },
    }
	fileSourceBackupFiles:= model.GetBackupFilesBodyFileSourceEnum().SELF_BUILD_OBS
	bucketNameBackupFiles:= "bucketName"
	backupFilesbody := &model.BackupFilesBody{
		FileSource: &fileSourceBackupFiles,
		BucketName: &bucketNameBackupFiles,
		Files: listFilesBackupFiles,
	}
	descriptionCreateMigrationTaskBody:= "Test"
	request.Body = &model.CreateMigrationTaskBody{
		TargetInstance: targetInstancebody,
		BackupFiles: backupFilesbody,
		MigrationMethod: model.GetCreateMigrationTaskBodyMigrationMethodEnum().FULL_AMOUNT_MIGRATION,
		MigrationType: model.GetCreateMigrationTaskBodyMigrationTypeEnum().BACKUPFILE_IMPORT,
		Description: &descriptionCreateMigrationTaskBody,
		TaskName: "migration1",
	}
	response, err := client.CreateMigrationTask(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

Backup import task created.

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.