All Products
Search
Document Center

Data Online Migration:Jobs

Last Updated:Feb 07, 2026

This topic describes how to use the SDK to call job-related methods.

Create a job

Note
  • This method is primarily used to create a migration job.

  • After creating a job, call Update job to start it.

The following sample code creates a job.

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 store your AccessKey ID and AccessKey secret in your project code. Doing so may expose your credentials and compromise all resources under your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")

/** Enter your Alibaba Cloud account ID. */
var userId = "11470***876***55"

func main() {
    // This example uses the China (Beijing) region.
    endpoint := "cn-beijing.mgw.aliyuncs.com"
    // HTTP and HTTPS are supported. HTTPS is used by default if not specified.
    protocol := "http"
    // Enter a job name.
    jobName := "examplejob"
    // Enter the source data address name.
    srcAddress := "examplesrcaddress"
    // Enter the destination data address name.
    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
    }
    /**
      overwriteMode and transferMode must be used together. The combinations mean:
      always,all: full overwrite
      always,lastmodified: overwrite based on file last modified time
      never,"": no overwrite
    */
    /* File overwrite mode. Valid values: 1. never  2. always */
    overwriteMode := "always"
    /* 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 unset, it defaults to a system value. If MaxBandWidth is 0 or unset, it also defaults to a system value. maxBandWidth is in bits.
    importQos := mgwpackage.ImportQos{
        MaxImportTaskQps: &maxImportTaskQps,
        MaxBandWidth:     &maxBandWidth,
    }

    // Configure filter rules, including file type filters, key filters, and time filters. See the API documentation for parameter details.
    // File type filters apply to localfs.
    excludeSymlink := false
    excludeDir := false
    fileTypeFilters := &mgwpackage.FileTypeFilters{
        &excludeDir, &excludeSymlink,
    }

    // Key filters. Set values 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 filters use UTC format. Set values 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 scheduling rules. See the API documentation for parameter details.
    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 job

Note

After creating a job, use this method to start, pause, or stop the job, or adjust its rate-limiting settings.

The following sample code updates a job's status.

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 store your AccessKey ID and AccessKey secret in your project code. Doing so may expose your credentials and compromise all resources under your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")

/** Enter your Alibaba Cloud account ID. */
var userId = "11470***876***55"

func main() {
    // This example uses the China (Beijing) region.
    endpoint := "cn-beijing.mgw.aliyuncs.com"
    // HTTP and HTTPS are supported. HTTPS is used by default if not specified.
    protocol := "http"
    // Enter a job 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: IMPORT_JOB_LAUNCHING (launch job), IMPORT_JOB_SUSPEND (pause job), IMPORT_JOB_CLOSING (shut down job).
    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
    }
}

The following sample code updates a job's rate limits.

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 store your AccessKey ID and AccessKey secret in your project code. Doing so may expose your credentials and compromise all resources under your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")

/** Enter your Alibaba Cloud account ID. */
var userId = "11470***876***55"

func main() {
    // This example uses the China (Beijing) region.
    endpoint := "cn-beijing.mgw.aliyuncs.com"
    // HTTP and HTTPS are supported. HTTPS is used by default if not specified.
    protocol := "http"
    // Enter the job name. This parameter 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 job details

Note

This method retrieves migration job details.

The following sample code retrieves details for a specific job by job 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 store your AccessKey ID and AccessKey secret in your project code. Doing so may expose your credentials and compromise all resources under your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")

/** Enter your Alibaba Cloud account ID. */
var userId = "11470***876***55"

func main() {
    // This example uses the China (Beijing) region.
    endpoint := "cn-beijing.mgw.aliyuncs.com"
    // HTTP and HTTPS are supported. HTTPS is used by default if not specified.
    protocol := "http"
    // Enter a job 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("covert failed: %v", err)
        return
    }
    fmt.Println(string(jsonBytes))
}

The following sample code retrieves details for a specific job by job ID.

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 store your AccessKey ID and AccessKey secret in your project code. Doing so may expose your credentials and compromise all resources under your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")

/** Enter your Alibaba Cloud account ID. */
var userId = "11470***876***55"

func main() {
    // This example uses the China (Beijing) region.
    endpoint := "cn-beijing.mgw.aliyuncs.com"
    // HTTP and HTTPS are supported. HTTPS is used by default if not specified.
    protocol := "http"
    // Enter the job ID. This parameter 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("covert failed: %v", err)
        return
    }
    fmt.Println(string(jsonBytes))
}

Sample success 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 jobs

Note

This method lists all migration jobs in the region for your account.

The following sample code lists all jobs under your account.

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 store your AccessKey ID and AccessKey secret in your project code. Doing so may expose your credentials and compromise all resources under your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")

/** Enter your Alibaba Cloud account ID. */
var userId = "11470***876***55"

func main() {
    // This example uses the China (Beijing) region.
    endpoint := "cn-beijing.mgw.aliyuncs.com"
    // HTTP and HTTPS are supported. HTTPS is used by default if not specified.
    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("covert failed: %v", err)
        return
    }
    fmt.Println(string(jsonBytes))
}

Sample success response

{
  "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 job retry information

Note
  • After a job finishes, some files might fail. Data Online Migration generates a manifest of these failed files. Use the following sample code to retrieve manifest details for a specific run. If the response shows Ready, you can retry the failed files using this manifest.

  • Use the result of this method when configuring parameters for retrying a job.

  • This method checks whether failed files from a migration job can be retried.

The following sample code retrieves retry information for a specific job run.

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 store your AccessKey ID and AccessKey secret in your project code. Doing so may expose your credentials and compromise all resources under your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")

/** Enter your Alibaba Cloud account ID. */
var userId = "11470***876***55"

func main() {
    // This example uses the China (Beijing) region.
    endpoint := "cn-beijing.mgw.aliyuncs.com"
    // HTTP and HTTPS are supported. HTTPS is used by default if not specified.
    protocol := "http"
    // Enter a job name.
    jobName := "examplejob"
    // Enter the job run ID.
    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("covert failed: %v", err)
        return
    }
    fmt.Println(string(jsonBytes))
}

Sample success 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 job history

Note

This method queries the history of a specific job.

The following sample code lists the history of a specific job.

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 store your AccessKey ID and AccessKey secret in your project code. Doing so may expose your credentials and compromise all resources under your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")

/** Enter your Alibaba Cloud account ID. */
var userId = "11470***876***55"

func main() {
    // This example uses the China (Beijing) region.
    endpoint := "cn-beijing.mgw.aliyuncs.com"
    // HTTP and HTTPS are supported. HTTPS is used by default if not specified.
    protocol := "http"
    // Enter a job name.
    jobName := "examplejob"
    // Enter the job run ID. If omitted, all runs for the job are listed.
    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 parameters 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("covert failed: %v", err)
        return
    }
    fmt.Println(string(jsonBytes))
}

Sample success 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 job

Note

This method deletes a migration job.

The following sample code deletes a specific job.

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 store your AccessKey ID and AccessKey secret in your project code. Doing so may expose your credentials and compromise all resources under your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")

/** Enter your Alibaba Cloud account ID. */
var userId = "11470***876***55"

func main() {
    // This example uses the China (Beijing) region.
    endpoint := "cn-beijing.mgw.aliyuncs.com"
    // HTTP and HTTPS are supported. HTTPS is used by default if not specified.
    protocol := "http"
    // Enter a job 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 job migration report

Note

This is an asynchronous method. After calling it, the backend starts preparing the migration report. Use the Get job migration report method to check whether the report is ready.

The following sample code creates a migration report for a specific job.

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 store your AccessKey ID and AccessKey secret in your project code. Doing so may expose your credentials and compromise all resources under your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")

/** Enter your Alibaba Cloud account ID. */
var userId = "11470***876***55"

func main() {
    // This example uses the China (Beijing) region.
    endpoint := "cn-beijing.mgw.aliyuncs.com"
    // HTTP and HTTPS are supported. HTTPS is used by default if not specified.
    protocol := "http"
    // Enter a job name.
    jobName := "examplejob"
    // Enter the job ID. This parameter is required.
    version := "b4155550-****-4371-****-9c7337348021"
    // Enter the job run ID. This parameter 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 job migration report

Note

Call this method to retrieve a migration report for a specific job. Use it to check whether the report is ready and to obtain the report.

The following sample code retrieves a migration report for a specific job.

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 store your AccessKey ID and AccessKey secret in your project code. Doing so may expose your credentials and compromise all resources under your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")

/** Enter your Alibaba Cloud account ID. */
var userId = "11470***876***55"

func main() {
    // This example uses the China (Beijing) region.
    endpoint := "cn-beijing.mgw.aliyuncs.com"
    // HTTP and HTTPS are supported. HTTPS is used by default if not specified.
    protocol := "http"
    // Enter the job ID. This parameter is required.
    version := "b4155550-****-4371-****-9c7337348021"
    // Enter the job run ID. This parameter 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("covert failed: %v", err)
        return
    }
    fmt.Println(string(jsonBytes))
}

Sample success response

{
  "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."
  }
}