备份管理(新)
更新时间:2024-10-14
备份管理
修改备份策略
使用以下代码修改备份策略。
public void modifyBackup(RdsClient rdsClient) {
RdsModifyBackupRequest request = new RdsModifyBackupRequest();
//指定实例 ID,必选
request.setInstanceId("rds-h1XXr7xq");
//以英文半角逗号分隔的备份时日间,周日为第一天,取值0
举例:"0,1,2,3,5,6",必选
request.setBackupDays("0");
//备份开始时间,这里的时间是用的UTC时间,必选
request.setBackupTime("17:00:00Z");
//是否启用备份数据持久化,必选
request.setPersistent(true);
//数据备份保留时长,范围1-730天;未启用则为0或不填,可选
request.setExpireInDays(10);
//日志备份保留时长,范围1-730天;未启用则为0或不填,可选
request.setLogBackupRetainDays(10);
//是否开启高频备份,默认为 false,可选
request.setIncrementalDataBackupEnable(true);
//增量数据备份间隔(秒)最小粒度是小时级别,开启高频备份后必传,值需要可以被3600整除,可选
request.setIncrementalDataBackupInterval(6);
//最新数据备份保留天数(实例删除后),天级别,不传默认0天,可选
request.setLatestDataBackupRetainDays(3);
//增量备份保留时长,可选
request.setRetentionPeriod(10);
//增量备份保留策略时长单位,取值为 week、month,默认为 week,可选
request.setTimeUnit("week");
AbstractBceResponse response = rdsClient.modifyBackup(request);
print("modifyBackup", response);
}
查询备份列表
使用以下代码可以查询指定实例的备份列表。
public void getBackupList(RdsClient rdsClient) {
RdsGetBackupListRequest request = new RdsGetBackupListRequest();
//实例ID列表,必选
request.setInstanceId("rds-h1XXr7xq");
//查找的分页的backupId,默认值为-1,表示第一页,可选
request.setMarker("-1");
//每一页的分页条数,默认值为1000
request.setMaxKeys(1000);
RdsGetBackupListResponse backupList = rdsClient.getBackupList(request);
print("getBackupList", backupList);
}
查询备份信息
使用以下代码可以查询备份信息。
public void getBackupInfo(RdsClient rdsClient) {
RdsBackupInfoRequest request = new RdsBackupInfoRequest();
//实例 ID,必选
request.setInstanceId("rds-h1XXr7xq");
//备份 ID,必选
request.setBackupId("1689087605048013371");
RdsBackupInfoResponse backupInfo = rdsClient.getBackupInfo(request);
print("getBackupInfo", backupInfo);
}
按备份集进行库表恢复
使用以下代码可以按备份集进行库表恢复
public void recoverForBackUpSet(RdsClient rdsClient) {
RdsRecoverForBackUpSetRequest request = new RdsRecoverForBackUpSetRequest();
//实例ID,必选
request.setInstanceId("rds-JC7L0yFI");
//源实例ID,与URL参数instanceId一样,可以不写,可选
request.setSourceInstanceId("rds-1Cm4tVAO");
//恢复指定的实例ID,忽略此参数默认恢复到原实例,可选
request.setTargetInstanceId("rds-1Cm4tVAO");
//备份 ID,必选
request.setSnapshotId("1720637060912738501");
//要恢复的数据信息,必选
List<RecoveryToSourceInstanceModel> datas = new ArrayList<>();
RecoveryToSourceInstanceModel data = new RecoveryToSourceInstanceModel();
List<RecoveryToSourceInstanceTableModel> tables = new ArrayList<>();
RecoveryToSourceInstanceTableModel table = new RecoveryToSourceInstanceTableModel();
//需要恢复的表名,必选
table.setTableName("newcxtest");
//恢复后表名,必选
table.setNewTablename("cxtest");
//需要恢复的库名称,必选
data.setDbName("newdeadlock");
////恢复后库名称。恢复至原实例时,dbName和newDbname不一样。恢复至指定实例时,dbName和newDbname可以一样,必选
data.setNewDbname("deadlock");
data.setRestoreMode("table");
data.setTables(tables);
datas.add(data);
request.setData(datas);
AbstractBceResponse response = rdsClient.recoverForBackUpSet(request);
print("recoverForBackUpSet", response);
}
按时间点进行库表恢复
可以使用以下代码按时间点进行库表恢复
public void recoverForTimeNode(RdsClient rdsClient) {
RdsRecoverForTimeNodeRequest request = new RdsRecoverForTimeNodeRequest();
//实例ID,必选
request.setInstanceId("rds-1Cm4tVAO");
//与instanceId是一样的,此项不用填写,可选
request.setSourceInstanceId("rds-1Cm4tVAO");
//要恢复的实例ID。 恢复到指定实例时,必填,值为指定的实例ID,如果恢复到原有实例,可以不写,可选
request.setTargetInstanceId("rds-1Cm4tVAO");
//备份时间点,必选
request.setDatetime("2024-07-10T18:36:46Z");
//要恢复的数据信息,必选
List<RecoveryToSourceInstanceModel> datas = new ArrayList<>();
RecoveryToSourceInstanceModel data = new RecoveryToSourceInstanceModel();
//表的对象集合,当restoreMode为table必填项,恢复目标实例 为database必项为非填项,可选
List<RecoveryToSourceInstanceTableModel> tables = new ArrayList<>();
RecoveryToSourceInstanceTableModel table = new RecoveryToSourceInstanceTableModel();
//需要恢复的表名,必选
table.setTableName("deadlock");
//恢复后表名,必选
table.setNewTablename("newdeadlock");
tables.add(table);
//需要恢复的库名称,必选
data.setDbName("cxtest");
//恢复后库名称。恢复至原实例时,dbName和newDbname不一样。恢复至指定实例时,dbName和newDbname可以一样,必选
data.setNewDbname("newcxtest");
//恢复模式,database(数据库),table(表)任选其一,必选
data.setRestoreMode("table");
data.setTables(tables);
datas.add(data);
request.setData(datas);
AbstractBceResponse response = rdsClient.recoverForTimeNode(request);
print("recoverForTimeNode", response);
}
获取binlog信息
使用以下代码可以获取binlog信息
public void getBinLogInfo(RdsClient rdsClient) {
RdsGetBinLogInfoRequest request = new RdsGetBinLogInfoRequest();
//实例ID,必选
request.setInstanceId("rds-1Cm4tVAO");
//binlogId,必选
request.setLogId("1720685193973036601");
//下载有效时间(S),必选
request.setDownloadValidTimeInSec("1800");
AbstractBceResponse response = rdsClient.getBinLogInfo(request);
print("getBinLogInfo", response);
}
获取binlog列表
使用以下代码可以获取binlog列表
public void getBinLogList(RdsClient rdsClient) {
RdsGetBinLogListRequest request = new RdsGetBinLogListRequest();
//实例 ID,必选
request.setInstanceId("rds-1Cm4tVAO");
//日志列表备份开始时间,UTC时间,必选
request.setDatetime("2024-07-11T06:48:29Z");
AbstractBceResponse response = rdsClient.getBinLogList(request);
print("getBinLogList", response);
}
删除指定的备份集
使用以下代码可以删除指定的备份集
public void deleteTheSpecifiedBackupSet(RdsClient rdsClient) {
RdsDeleteSpecifiedBackUpRequest request = new RdsDeleteSpecifiedBackUpRequest();
//实例ID,必选
request.setInstanceId("rdsmsn17thg0i4p");
//手动全量备份 ID,必选
request.setSnapshotId("1720671279584629601");
AbstractBceResponse response = rdsClient.deleteTheSpecifiedBackupSet(request);
print("deleteTheSpecifiedBackupSet", response);
}
手动发起全量的物理备份
使用以下代码可以手动发起全量的物理备份
public void manuallyInitiateFullPhysicalBackup(RdsClient rdsClient) {
RdsFullPhysicalBackupRequest request = new RdsFullPhysicalBackupRequest();
//实例 ID,必选
request.setInstanceId("rds-5WIldjI3");
//窗口字段。操作执行方式,有两种取值:timewindow、immediate。
//其中timewindow表示在时间窗口内执行,immediate表示立即执行。默认为immediate。实例默认的时间窗口为05:00~06:00,可选
request.setEffectiveTime("timewindow");
//备份类型,支持physical/snapshot, 取值为:snapshot,磁盘类型为ssd将不支持快照备份,可选
request.setDataBackupType("physical");
AbstractBceResponse response = rdsClient.manuallyInitiateFullPhysicalBackup(request);
print("manuallyInitiateFullPhysicalBackup", response);
}