Create, update, query, list, and delete migration tasks, manage migration reports, and retry failed file migrations by using the Data Online Migration Go SDK.
Before you begin
All code examples in this topic use the following common setup. Configure authentication and initialize the client before you call any task management method.
package main
import (
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Enter the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
Client initialization:
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify a protocol, HTTPS is used by default.
protocol := "http"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
The endpoint follows the format {region}.mgw.aliyuncs.com. Replace cn-beijing with the region where your migration resources reside.
Create a task
-
This method creates a migration task. For more information, see CreateJob.
-
After you create the task, you must update its status to start it.
Overwrite and transfer mode combinations
The overwriteMode and transferMode parameters must be used together. The following table lists the valid combinations.
overwriteMode |
transferMode |
Behavior |
|---|---|---|
always |
all |
Overwrites all files. |
always |
lastmodified |
Overwrites files based on their last modified time. |
never |
"" (empty string) |
Does not overwrite files. |
Valid values for overwriteMode: never, always
Valid values for transferMode: changed, all, lastmodified
Rate limiting (ImportQos)
| Parameter | Description | Default |
|---|---|---|
MaxImportTaskQps |
Maximum QPS for import tasks. | Used if set to 0 or not set. |
MaxBandWidth |
Maximum bandwidth in bits (not bytes). | Used if set to 0 or not set. |
Filter rules (FilterRule)
| Filter type | Description | Note |
|---|---|---|
FileTypeFilters |
Exclude symlinks or directories. | Applicable to local file systems (localfs) only |
KeyFilters |
Include or exclude files by regex pattern. | - |
LastModifiedFilters |
Include or exclude files by last modified time range (UTC). | - |
Scheduling rule (ScheduleRule)
| Parameter | Description | Example |
|---|---|---|
MaxScheduleCount |
Maximum number of scheduled executions. | 5 |
StartCronExpression |
Cron expression for task start time. | 0 0 10 * * ? |
SuspendCronExpression |
Cron expression for task suspension time. | 0 0 14 * * ? |
Sample code
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Enter the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify a protocol, HTTPS is used by default.
protocol := "http"
// Enter the task name.
jobName := "examplejob"
// Enter the name of the source data address.
srcAddress := "examplesrcaddress"
// Enter the name of the destination data address.
destAddress := "exampledestaddress"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
/**
The overwriteMode and transferMode parameters must be used together. The combinations have the following meanings:
always, all: Overwrites all files.
always, lastmodified: Overwrites files based on their last modified time.
never, "": Does not overwrite files.
*/
/* The file overwrite mode. Valid values: 1. never 2. always */
overwriteMode := "always"
/* The file transfer mode. Valid values: 1. changed 2. all 3. lastmodified */
transferMode := "lastmodified"
// Set maxBandWidth and maxImportTaskQps as needed.
maxImportTaskQps := int64(1000)
maxBandWidth := int64(2147483648)
// If maxImportTaskQps is 0 or not set, the default value is used. If MaxBandWidth is 0 or not set, the default value is used. The unit of maxBandWidth is bits.
importQos := mgwpackage.ImportQos{
MaxImportTaskQps: &maxImportTaskQps,
MaxBandWidth: &maxBandWidth,
}
// Configure filter rules, including file type filters, file filters, and time filters. For more information about the parameters, see the API documentation.
// File type filter, applicable to local file systems (localfs).
excludeSymlink := false
excludeDir := false
fileTypeFilters := &mgwpackage.FileTypeFilters{
&excludeDir, &excludeSymlink,
}
// File filter. Set this filter as needed.
var includeRegex []*string
var excludeRegex []*string
jpgFile := ".*.jpg"
gifFile := ".*.gif"
txtFile := ".*.txt"
jsFile := ".*.js"
includeRegex = append(includeRegex, &jpgFile, &gifFile)
excludeRegex = append(excludeRegex, &txtFile, &jsFile)
KeyFilters := &mgwpackage.KeyFilters{
Excludes: &mgwpackage.KeyFilterItem{
excludeRegex,
}, Includes: &mgwpackage.KeyFilterItem{
includeRegex,
},
}
// Time filter. The time must be in UTC format. Set this filter as needed.
includeStartTime := "2006-01-01T00:00:00Z"
includeEndTime := "2007-01-01T00:00:00Z"
excludeStartTime := "2009-01-01T00:00:00Z"
excludeEndTime := "2010-01-01T00:00:00Z"
includeTimeFilter := []*mgwpackage.TimeFilter{{
&includeStartTime, &includeEndTime,
}}
includeLastModifyFilters := &mgwpackage.LastModifyFilterItem{
includeTimeFilter,
}
excludeTimeFilter := []*mgwpackage.TimeFilter{{
EndTime: &excludeStartTime, StartTime: &excludeEndTime,
}}
excludeLastModifyFilters := &mgwpackage.LastModifyFilterItem{
TimeFilter: excludeTimeFilter,
}
lastModifiedFilters := &mgwpackage.LastModifiedFilters{
Excludes: excludeLastModifyFilters, Includes: includeLastModifyFilters,
}
filterRule := mgwpackage.FilterRule{
LastModifiedFilters: lastModifiedFilters,
KeyFilters: KeyFilters,
FileTypeFilters: fileTypeFilters,
}
// Configure the scheduling rule. For more information about the parameters, see the API documentation.
maxScheduleCount := int64(5)
startCronExpression := "0 0 10 * * ?"
suspendCronExpression := "0 0 14 * * ?"
scheduleRule := mgwpackage.ScheduleRule{
MaxScheduleCount: &maxScheduleCount,
StartCronExpression: &startCronExpression,
SuspendCronExpression: &suspendCronExpression,
}
_, err = client.CreateJob(&userId, &mgwpackage.CreateJobRequest{ImportJob: &mgwpackage.CreateJobInfo{
Name: &jobName,
TransferMode: &transferMode,
OverwriteMode: &overwriteMode,
SrcAddress: &srcAddress,
DestAddress: &destAddress,
ImportQos: &importQos,
FilterRule: &filterRule,
ScheduleRule: &scheduleRule,
}})
if err != nil {
log.Printf("create job failed: %v", err)
return
}
}
Update a task
After you create a task, use this method to start, pause, or close the task and to adjust rate limiting settings.
Update the task status
Set the Status field to one of the following values:
| Status value | Action |
|---|---|
IMPORT_JOB_LAUNCHING |
Start the task. |
IMPORT_JOB_SUSPEND |
Pause the task. |
IMPORT_JOB_CLOSING |
Close the task. |
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Enter the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify a protocol, HTTPS is used by default.
protocol := "http"
// Enter the task name.
jobName := "examplejob"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
// Valid status values are IMPORT_JOB_LAUNCHING (start the task), IMPORT_JOB_SUSPEND (pause the task), and IMPORT_JOB_CLOSING (close the task).
status := "IMPORT_JOB_LAUNCHING"
_, err = client.UpdateJob(&userId, &jobName, &mgwpackage.UpdateJobRequest{
&mgwpackage.UpdateJobInfo{Status: &status},
})
if err != nil {
log.Printf("update job failed, %v", err)
return
}
}
Update rate limiting settings
Adjust MaxBandWidth (in bits) and MaxImportTaskQps for a task.
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Enter the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify a protocol, HTTPS is used by default.
protocol := "http"
// Enter the task ID. This is required.
jobName := "examplejob"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
// Set maxBandWidth and maxImportTaskQps as needed.
maxBandWidth := int64(1610612736)
maxImportTaskQps := int64(1500)
_, err = client.UpdateJob(&userId, &jobName, &mgwpackage.UpdateJobRequest{
&mgwpackage.UpdateJobInfo{
ImportQos: &mgwpackage.ImportQos{
MaxBandWidth: &maxBandWidth,
MaxImportTaskQps: &maxImportTaskQps,
},
},
})
if err != nil {
log.Printf("update job failed: %v", err)
return
}
}
Get task details
Retrieve the details of a migration task by task name or task ID.
Get a task by name
package main
import (
"encoding/json"
"fmt"
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Enter the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify a protocol, HTTPS is used by default.
protocol := "http"
// Enter the task name.
jobName := "examplejob"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
resp, err := client.GetJob(&userId, &jobName, &mgwpackage.GetJobRequest{})
if err != nil {
log.Printf("get job failed: %v", err)
return
}
jsonBytes, err := json.Marshal(resp)
if err != nil {
log.Printf("convert failed: %v", err)
return
}
fmt.Println(string(jsonBytes))
}
Get a task by ID
Pass the task ID instead of the task name, and set ByVersion to an empty string.
package main
import (
"encoding/json"
"fmt"
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Enter the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify a protocol, HTTPS is used by default.
protocol := "http"
// Enter the task ID. This is required.
jobId := "b4155550-****-4371-****-9c7337348021"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
byVersion := ""
resp, err := client.GetJob(&userId, &jobId, &mgwpackage.GetJobRequest{
ByVersion: &byVersion,
})
if err != nil {
log.Printf("get job failed: %v", err)
return
}
jsonBytes, err := json.Marshal(resp)
if err != nil {
log.Printf("convert failed: %v", err)
return
}
fmt.Println(string(jsonBytes))
}
Sample response
{
"ImportJob": {
"Name": "test_name",
"SrcAddress": "test_src_address",
"DestAddress": "test_dest_address",
"Status": "IMPORT_JOB_DOING",
"EnableMultiVersioning": false,
"CreateTime": "2024-05-01T12:00:00.000Z",
"ModifyTime": "2024-05-01T12:00:00.000Z",
"Version": "test_id",
"Audit": {
"LogMode": "off"
},
"OverwriteMode": "always",
"TransferMode": "all",
"Tags": "K1:V1,K2:V2",
"ParentName": "test_parent_name",
"ParentVersion": "7db93837-a5ee-4e3a-b3c8-800e7947dabc",
"ConvertSymlinkTarget": false,
"CreateReport": false,
"Owner": "test_owner",
"FilterRule": {
"KeyFilters": {
"Includes": {
"Regex": [
".*\\.jpg$"
]
},
"Excludes": {
"Regex": [
".*\\.jpg$"
]
}
},
"LastModifiedFilters": {
"Includes": {
"TimeFilter": [
{
"StartTime": "2006-01-01T00:00:00Z",
"EndTime": "2006-12-31T59:59:59Z"
}
]
},
"Excludes": {
"TimeFilter": [
{
"StartTime": "2006-01-01T00:00:00Z",
"EndTime": "2006-12-31T59:59:59Z"
}
]
}
},
"FileTypeFilters": {
"ExcludeSymlink": true,
"ExcludeDir": true
}
},
"ImportQos": {
"MaxBandWidth": 1073741824,
"MaxImportTaskQps": 1000
},
"ScheduleRule": {
"StartCronExpression": "0 0 * * * ?",
"SuspendCronExpression": "0 0 * * * ?",
"MaxScheduleCount": 1
}
}
}
List tasks
List all migration tasks for the current user in a specified region. Use Count and Marker for pagination.
package main
import (
"encoding/json"
"fmt"
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Enter the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify a protocol, HTTPS is used by default.
protocol := "http"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
// Set marker and count as needed.
count := int32(1)
marker := ""
resp, err := client.ListJob(&userId, &mgwpackage.ListJobRequest{
Count: &count,
Marker: &marker,
})
if err != nil {
log.Printf("list job failed: %v", err)
return
}
jsonBytes, err := json.Marshal(resp)
if err != nil {
log.Printf("convert failed: %v", err)
return
}
fmt.Println(string(jsonBytes))
}
Sample response
The response includes an ImportJobList object. If Truncated is true, use NextMarker as the Marker value in the next request to retrieve the remaining results.
{
"ImportJobList": {
"NextMarker": "test_nex_marker",
"Truncated": true,
"ImportJob": [
{
"Name": "test_name",
"SrcAddress": "test_src_address",
"DestAddress": "test_dest_address",
"Status": "IMPORT_JOB_DOING",
"EnableMultiVersioning": false,
"CreateTime": "2024-05-01T12:00:00.000Z",
"ModifyTime": "2024-05-01T12:00:00.000Z",
"Version": "test_id",
"Audit": {
"LogMode": "off"
},
"OverwriteMode": "always",
"TransferMode": "all",
"Tags": "K1:V1,K2:V2",
"ParentName": "test_parent_name",
"ParentVersion": "7db93837-a5ee-4e3a-b3c8-800e7947dabc",
"ConvertSymlinkTarget": false,
"CreateReport": false,
"Owner": "test_owner",
"FilterRule": {
"KeyFilters": {
"Includes": {
"Regex": [
".*\\.jpg$"
]
},
"Excludes": {
"Regex": [
".*\\.jpg$"
]
}
},
"LastModifiedFilters": {
"Includes": {
"TimeFilter": [
{
"StartTime": "2006-01-01T00:00:00Z",
"EndTime": "2006-12-31T59:59:59Z"
}
]
},
"Excludes": {
"TimeFilter": [
{
"StartTime": "2006-01-01T00:00:00Z",
"EndTime": "2006-12-31T59:59:59Z"
}
]
}
},
"FileTypeFilters": {
"ExcludeSymlink": true,
"ExcludeDir": true
}
},
"ImportQos": {
"MaxBandWidth": 1073741824,
"MaxImportTaskQps": 1000
},
"ScheduleRule": {
"StartCronExpression": "0 0 * * * ?",
"SuspendCronExpression": "0 0 * * * ?",
"MaxScheduleCount": 1
}
}
]
}
}
Get task retry information
-
After a task runs, some files may fail to migrate. Data Online Migration creates a checklist of these failed files. You can use this method to retrieve the checklist for a specific task round. If
ReadyRetryreturnsReady, you can use the checklist to retry migrating the failed files. -
The response provides the parameters needed to create a retry task.
-
This method checks whether failed files from a migration task can be retried.
The following sample code retrieves the retry information for a task in a specific round.
package main
import (
"encoding/json"
"fmt"
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Enter the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify a protocol, HTTPS is used by default.
protocol := "http"
// Enter the task name.
jobName := "examplejob"
// Enter the task round.
runtimeId := int32(1)
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
resp, err := client.GetJobResult(&userId, &jobName, &mgwpackage.GetJobResultRequest{
RuntimeId: &runtimeId,
})
if err != nil {
log.Printf("get job result failed: %v", err)
return
}
jsonBytes, err := json.Marshal(resp)
if err != nil {
log.Printf("convert failed: %v", err)
return
}
fmt.Println(string(jsonBytes))
}
Sample response
When ReadyRetry is Ready, you can create a retry task using the inventory information (InvPath, InvBucket, InvDomain, etc.) from the response.
{
"ImportJobResult": {
"ReadyRetry": "Ready",
"InvPath": "mainfest.json",
"InvBucket": "test_sys_bucket",
"InvDomain": "test_domain",
"InvLocation": "oss",
"InvAccessId": "test_access_id",
"InvAccessSecret": "test_secret_key",
"InvRegionId": "test_region_id",
"AddressType": "ossinv",
"TotalObjectCount": 1000,
"CopiedObjectCount": 800,
"FailedObjectCount": 200,
"SkippedObjectCount": 200,
"TotalObjectSize": 1000,
"CopiedObjectSize": 800,
"SkippedObjectSize": 800,
"Version": "test_job_id"
}
}
List task history
Query the execution history of a specified task. Omit RuntimeId to list the history across all rounds.
The following sample code lists the execution history of a specified task.
package main
import (
"encoding/json"
"fmt"
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Enter the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify a protocol, HTTPS is used by default.
protocol := "http"
// Enter the task name.
jobName := "examplejob"
// Enter the task round. You can leave runtimeId unspecified to list the history of all rounds for the specified task.
runtimeId := int32(1)
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
// Set the following parameter values as needed.
count := int32(1)
marker := ""
resp, err := client.ListJobHistory(&userId, &jobName, &mgwpackage.ListJobHistoryRequest{
Count: &count,
Marker: &marker,
RuntimeId: &runtimeId,
})
if err != nil {
log.Printf("list job history failed: %v", err)
return
}
jsonBytes, err := json.Marshal(resp)
if err != nil {
log.Printf("convert failed: %v", err)
return
}
fmt.Println(string(jsonBytes))
}
Sample response
{
"JobHistoryList": {
"Truncated": "true",
"NextMarker": "test_next_marker",
"JobHistory": [
{
"Name": "test_name",
"JobVersion": "test_id",
"RuntimeId": "1",
"CommitId": "2",
"StartTime": "2024-05-01T12:00:00.000Z",
"EndTime": "2024-05-01T12:00:00.000Z",
"Status": "IMPORT_JOB_DOING",
"TotalCount": 1000,
"CopiedCount": 900,
"FailedCount": 100,
"TotalSize": 5368709120,
"CopiedSize": 4294967296,
"SkippedCount": 0,
"SkippedSize": 0,
"RuntimeState": "Normal",
"Message": "test error msg.",
"Operator": "user",
"ListStatus": "Listing"
}
]
}
}
Delete a task
Delete a migration task that you no longer need.
The following sample code deletes a specified task.
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Enter the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify a protocol, HTTPS is used by default.
protocol := "http"
// Enter the task name.
jobName := "examplejob"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
_, err = client.DeleteJob(&userId, &jobName, &mgwpackage.DeleteJobRequest{})
if err != nil {
log.Printf("delete job failed: %v", err)
return
}
}
Create a task migration report
This is an asynchronous call. After you call this method, the backend begins generating the migration report. To check whether the report is ready, call Get a task migration report.
The following sample code creates a migration report for a specific task.
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Enter the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify a protocol, HTTPS is used by default.
protocol := "http"
// Enter the task name.
jobName := "examplejob"
// Enter the task ID. This is required.
version := "b4155550-****-4371-****-9c7337348021"
// Enter the task round. This is required.
runtimeId := int32(1)
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
_, err = client.CreateReport(&userId, &mgwpackage.CreateReportRequest{
CreateReport: &mgwpackage.CreateReportInfo{
JobName: &jobName,
RuntimeId: &runtimeId,
Version: &version,
},
})
if err != nil {
log.Printf("create report failed: %v", err)
return
}
}
Get a task migration report
Retrieve the migration report for a specified task. The response indicates whether the report is generated and includes the report data if available.
The following sample code retrieves the migration report for a specified task.
package main
import (
"encoding/json"
"fmt"
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Enter the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify a protocol, HTTPS is used by default.
protocol := "http"
// Enter the task ID. This is required.
version := "b4155550-****-4371-****-9c7337348021"
// Enter the task round. This is required.
runtimeId := int32(1)
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
resp, err := client.GetReport(&userId, &mgwpackage.GetReportRequest{
RuntimeId: &runtimeId,
Version: &version,
})
if err != nil {
log.Printf("get report failed: %v", err)
return
}
jsonBytes, err := json.Marshal(resp)
if err != nil {
log.Printf("convert failed: %v", err)
return
}
fmt.Println(string(jsonBytes))
}
Sample response
The Status field indicates report generation progress. When the report is complete, the response includes file counts, timing data, and list prefixes for detailed file-level results.
{
"GetReportResponse": {
"Status": "Running",
"ReportCreateTime": "2024-05-01T12:00:00.000Z",
"ReportEndTime": "2024-05-01T12:00:00.000Z",
"TotalCount": 1000,
"CopiedCount": 800,
"SkippedCount": 100,
"FailedCount": 100,
"JobCreateTime": "2024-05-01T12:00:00.000Z",
"JobEndTime": "2024-05-01T12:00:00.000Z",
"JobExecuteTime": "1000",
"TotalListPrefix": "test_total_prefix/",
"SkippedListPrefix": "test_skipped_prefix/",
"FailedListPrefix": "test_failed_prefix/",
"ErrorMessage": "test error msg."
}
}