备份管理
更新时间:2024-03-14
获取备份列表
使用以下代码可以获取一个实例下的备份列表。
// import "github.com/baidubce/bce-sdk-go/services/rds"
args := &rds.GetBackupListArgs{}
_, err := client.GetBackupList(instanceId, args)
if err != nil {
fmt.Printf("get backup list error: %+v\n", err)
return
}
fmt.Printf("get backup list success\n")
注意:
- 请求参数 marker 和 maxKeys 不是必须的。
获取备份详情
使用以下代码可以获取一个实例备份的详情信息。
// import "github.com/baidubce/bce-sdk-go/services/rds"
result, err := client.GetBackupDetail(instanceId, backupId)
if err != nil {
fmt.Printf("get backup detail error: %+v\n", err)
return
}
fmt.Printf("get backup detail success\n")
删除备份
使用以下代码可以删除手动备份
// import "github.com/baidubce/bce-sdk-go/services/rds"
_, err := client.DeleteBackup(instanceId, backupId)
if err != nil {
fmt.Printf("delete backup detail error: %+v\n", err)
return
}
fmt.Printf("delete backup detail success\n")
更新备份策略
使用以下代码可以更新一个实例的备份策略。
// import "github.com/baidubce/bce-sdk-go/services/rds"
args := &rds.ModifyBackupPolicyArgs{
BackupDays: "1,3",
BackupTime: "10:00:00Z",
Persistent: true,
ExpireInDays: 20,
}
err := client.ModifyBackupPolicy(instanceId, args)
if err != nil {
fmt.Printf("modify backup policy error: %+v\n", err)
return
}
fmt.Printf("modify backup policy success\n")
获取binlog列表
使用以下代码可以获取binlog列表
// import "github.com/baidubce/bce-sdk-go/services/rds"
result, err := client.GetBinlogList(instanceId, detaTime)
if err != nil {
fmt.Printf("get binlog list error: %+v\n", err)
return
}
fmt.Printf("get binlog list success\n")
获取binlog信息
使用以下代码可以获取binlog信息
// import "github.com/baidubce/bce-sdk-go/services/rds"
result, err := client.GetBinlogInfo(instanceId, binlogId, downloadValidTimeInSec)
if err != nil {
fmt.Printf("get binlog detail error: %+v\n", err)
return
}
fmt.Printf("get binlog detail success\n")
按时间点进行库表恢复
使用以下代码可以按时间点进行库表恢复
// import "github.com/baidubce/bce-sdk-go/services/rds"
recoveryByDatetimeArgs := &RecoveryByDatetimeArgs{
Datetime: "2022-01-11T16:05:52Z",
Data: []RecoveryData{
{
DbName: "test_db",
NewDbname: "new_test_db",
RestoreMode: "database",
Tables: []TableData{
{
TableName: "table_name",
NewTablename: "new_table_name",
},
},
},
},
}
err := client.RecoveryToSourceInstanceByDatetime(instanceId, recoveryByDatetimeArgs)
if err != nil {
fmt.Printf("recovery by datetime error: %+v\n", err)
return
}
fmt.Printf("recovery by datetime success\n")
按备份集进行库表恢复
使用以下代码可以按备份集进行库表恢复
// import "github.com/baidubce/bce-sdk-go/services/rds"
recoveryBySnapshotArgs := &RecoveryBySnapshotArgs{
SnapshotId: "1691734023130272802",
Data: []RecoveryData{
{
DbName: "test_db",
NewDbname: "new_test_db",
RestoreMode: "database",
Tables: []TableData{
{
TableName: "table_name",
NewTablename: "new_table_name",
},
},
},
},
}
err := client.RecoveryToSourceInstanceBySnapshot(instanceId, recoveryBySnapshotArgs)
if err != nil {
fmt.Printf("recovery by snapshot error: %+v\n", err)
return
}
fmt.Printf("recovery by snapshot success\n")