阅读本文,您可以获取 Go SDK 数据迁移的接口调用示例,实现快速开发。
调用接口前,请先完成 Go SDK 的安装及初始化操作。
本节为您介绍数据迁移相关接口的功能和调用示例。
您可以调用 CreateImageMigrateTask 接口创建从源存储至 veImageX 的数据迁移任务。详细的参数说明可参见 CreateImageMigrateTask 接口文档。
接口调用示例如下所示。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_CreateImageMigrateTask(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.CreateImageMigrateTaskBody{} resp, err := instance.CreateImageMigrateTask(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }
您可以调用 GetImageMigrateTasks 接口分页获取当前账号下的迁移任务及其迁移详情。详细的参数说明可参见 GetImageMigrateTasks 接口文档。
接口调用示例如下所示。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_GetImageMigrateTasks(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.GetImageMigrateTasksQuery{} resp, err := instance.GetImageMigrateTasks(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }
您可以调用 UpdateImageTaskStrategy 接口指定任务 ID 来更新该任务的迁移策略。详细的参数说明可参见 UpdateImageTaskStrategy 接口文档。
接口调用示例如下所示。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_UpdateImageTaskStrategy(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.UpdateImageTaskStrategyBody{} resp, err := instance.UpdateImageTaskStrategy(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }
您可以调用 GetVendorBuckets 接口指定云服务商和访问密钥获取迁移源 Bucket 详情。详细的参数说明可参见 GetVendorBuckets 接口文档。
接口调用示例如下所示。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_GetVendorBuckets(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.GetVendorBucketsBody{} resp, err := instance.GetVendorBuckets(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }
您可以调用 TerminateImageMigrateTask 接口指定任务 ID 来结束该迁移任务。详细的参数说明可参见 TerminateImageMigrateTask 接口文档。
接口调用示例如下所示。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_TerminateImageMigrateTask(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.TerminateImageMigrateTaskQuery{} resp, err := instance.TerminateImageMigrateTask(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }
您可以调用 DeleteImageMigrateTask 接口指定任务 ID 来删除该迁移任务。详细的参数说明可参见 DeleteImageMigrateTask 接口文档。
接口调用示例如下所示。
import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_DeleteImageMigrateTask(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.DeleteImageMigrateTaskQuery{} resp, err := instance.DeleteImageMigrateTask(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }o
您可以调用 RerunImageMigrateTask 接口指定任务 ID 来重启该迁移任务(仅对状态为部分迁移完成的任务生效)。详细的参数说明可参见 RerunImageMigrateTask 接口文档。
接口调用示例如下所示。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_RerunImageMigrateTask(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.RerunImageMigrateTaskQuery{} resp, err := instance.RerunImageMigrateTask(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }
您可以调用 ExportFailedMigrateTask 接口指定迁移失败的任务 ID 来导出文件地址和迁移失败错误信息。详细的参数说明可参见 ExportFailedMigrateTask 接口文档。
接口调用示例如下所示。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_ExportFailedMigrateTask(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.ExportFailedMigrateTaskQuery{} resp, err := instance.ExportFailedMigrateTask(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }