Creating a Backup Import Task
Function
This API is used to create a backup import 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:create
Write
-
-
-
-
URI
POST /v2/{project_id}/migration-task
| 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 |
Request Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| task_name | Yes | String | Definition Backup import task name. Constraints N/A Range N/A Default Value N/A |
| description | No | String | Definition Backup import task description. Constraints N/A Range N/A Default Value N/A |
| migration_type | Yes | String | Definition Migration mode, which can be backup file import or online migration. Constraints N/A Range
Default Value N/A |
| migration_method | Yes | String | Definition Type of the migration, which can be full migration or incremental migration. Constraints In the backup import scenario, the migration type is fixed to full migration. Range Default Value N/A |
| backup_files | No | BackupFilesBody object | Definition Backup files to be imported when the migration mode is backup file import. Constraints This parameter is mandatory in the backup import scenario. The backup record corresponding to backup_id must exist and be valid. Range N/A Default Value N/A |
| network_type | No | String | Definition Type of the network for communication between the source and target Redis when the migration mode is online migration. This API is no longer available. Use the CreateOnlineMigrationTask API to create an online migration task. Constraints N/A Range N/A Default Value N/A |
| source_instance | No | SourceInstanceBody object | Definition Source Redis information. This parameter is mandatory when the migration mode is online data migration. This API is no longer available. Use the CreateOnlineMigrationTask API to create an online migration task. Source Redis connection information. This parameter is not used in the backup import scenario. Constraints N/A Range N/A Default Value N/A |
| target_instance | Yes | TargetInstanceBody object | Definition Target Redis information. Constraints This parameter is mandatory. The ID must be that of an existing DCS instance under the current tenant. Range N/A Default Value N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| file_source | Yes | String | Definition Backup file source. The source can be an OBS bucket or a backup record. Constraints N/A Range Default Value N/A |
| bucket_name | No | String | Definition OBS bucket name. Constraints This parameter is mandatory when the data source is an OBS bucket. Range N/A Default Value N/A |
| backup_id | No | String | Definition Backup record ID. Constraints This parameter is mandatory when the data source is a backup record. Range N/A Default Value N/A |
| 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. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| file_name | Yes | String | Definition Name of a backup file. Constraints N/A Range N/A Default Value N/A |
| size | No | String | Definition File size in bytes. Constraints N/A Range N/A Default Value N/A |
| update_at | No | String | Definition Time when the file is last modified. The format is YYYY-MM-DD HH:MM:SS. Constraints N/A Range N/A Default Value N/A |
| 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 |
| ip | No | String | Definition Redis IP address. This parameter is no longer used for V2 data migration APIs. Constraints N/A Range N/A Default Value N/A |
| port | No | String | Definition Redis port. This parameter is no longer used for V2 data migration APIs. Constraints N/A Range N/A Default Value N/A |
| addrs | Yes | String | Definition Source Redis instance name (specified in the source_instance parameter). 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 |
| name | No | String | Definition Redis instance name. Constraints N/A Range N/A Default Value N/A |
| proxy_multi_db | No | Boolean | Definition Whether multi-DB is enabled for a Proxy Cluster DCS instance. This parameter needs to be set to true if the source Redis instance is a multi-DB (multi-db set to yes) Proxy Cluster DCS Redis instance. In other scenarios, you do not need to set this parameter. Constraints If this parameter is set to true for a source Proxy Cluster instance without multi-DB, the task may fail. Range Default Value false |
| db | No | String | Definition Database number. It specifies the DB to be migrated. For example, if 5 is entered, only DB5 will be migrated. If this parameter is left empty, all DBs will be migrated. Constraints If this parameter is not empty, the value must be an integer. Range An integer ranging from 0 to 255. Default Value N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| id | Yes | String | Definition Redis instance ID (mandatory in the target_instance parameter). 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 |
| ip | No | String | Definition Redis IP address. This parameter is no longer used for V2 data migration APIs. Constraints N/A Range N/A Default Value N/A |
| port | No | String | Definition Redis port. This parameter is no longer used for V2 data migration APIs. Constraints N/A 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 |
| name | No | String | Definition Redis instance name (specified in the target_instance parameter). Constraints N/A Range N/A Default Value N/A |
| proxy_multi_db | No | Boolean | Definition Whether multi-DB is enabled for a Proxy Cluster DCS instance. You do not need to set this parameter. Constraints N/A Range Default Value N/A |
| db | No | String | Definition Database number. It specifies the DB to be migrated. For example, if 5 is entered, only DB5 will be migrated. If this parameter is left empty, all DBs will be migrated. Constraints If this parameter is not empty, the value must be an integer. Range An integer ranging from 0 to 255. Default Value N/A |
Response Parameters
Status code: 200
| 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 |
| error | String | Definition Error information. Range N/A |
Status code: 400
| 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
| 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
| 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
| 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
| 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
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" : "790526976",
"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.
Java
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("790526976") ); 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.CreateMigrationTaskBody.fromValue("full_amount_migration")); body.withMigrationType(CreateMigrationTaskBody.CreateMigrationTaskBody.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()); } } } |
Python
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="790526976" ) ] 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) |
Go
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 72 73 74 75 76 77 78 79 | 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.CreateMigrationTaskRequest{} nameTargetInstance:= "dcs-test" passwordTargetInstance:= "xxxxxx" targetInstancebody := &model.TargetInstanceBody{ Id: "d2c8399f-bdba-43c1-8069-3ff17a1a79d5", Name: &nameTargetInstance, Password: &passwordTargetInstance, } sizeFiles:= "790526976" 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) } } |
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 | 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.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot