feat(rds): restore DB instances and clusters to a point in time (#4963)

Serve RestoreDBInstanceToPointInTime and RestoreDBClusterToPointInTime,
and report the restorable window: LatestRestorableTime on
DescribeDBInstances, EarliestRestorableTime and LatestRestorableTime on
DescribeDBClusters.

Requests are checked as the API reference describes: exactly one of
RestoreTime (RestoreToTime) and UseLatestRestorableTime, a time inside
the window or InvalidRestoreFault, PointInTimeRestoreNotEnabled for an
instance with backups off, and exactly one source. An instance source is
named by identifier or DbiResourceId, a cluster source by identifier, ARN
or DbClusterResourceId; automated backups ARNs answer
DBInstanceAutomatedBackupNotFound since no automated backups are kept.

Floci keeps no transaction log, so the target is seeded from a
pg_dumpall of the source taken when the request arrives, as read
replicas are. The restored data is the source's latest state for any
time in the window, and LatestRestorableTime is the current time. Only
PostgreSQL sources are accepted, as for CreateDBSnapshot.

Closes #4952
This commit is contained in:
David authored and GitHub committed 2026-10-03 15:43:02 -04:00
1 parent 823f8751de
commit 9c49ecf255
9 files changed
+959 -2

No files matched your search

@@ -32,6 +32,7 @@ import software.amazon.awssdk.services.rds.model.DescribeDbSubnetGroupsResponse;
import software.amazon.awssdk.services.rds.model.DescribeOptionGroupsResponse;
import software.amazon.awssdk.services.rds.model.DescribeOrderableDbInstanceOptionsResponse;
import software.amazon.awssdk.services.rds.model.InvalidOptionGroupStateException;
import software.amazon.awssdk.services.rds.model.InvalidRestoreException;
import software.amazon.awssdk.services.rds.model.ListTagsForResourceResponse;
import software.amazon.awssdk.services.rds.model.ModifyDbClusterResponse;
import software.amazon.awssdk.services.rds.model.ModifyDbProxyResponse;
@@ -44,6 +45,7 @@ import software.amazon.awssdk.services.rds.model.RdsException;
import software.amazon.awssdk.services.rds.model.RegisterDbProxyTargetsResponse;
import software.amazon.awssdk.services.rds.model.Tag;
import java.time.Instant;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -611,6 +613,69 @@ class RdsControlPlaneTest {
}
}
@Test
@DisplayName("Point in time restore of an instance and a cluster, and the restorable times")
void sdkRestoresAnInstanceAndAClusterToAPointInTime() {
String instanceName = TestFixtures.uniqueName("rds-pitr-db");
String restoredInstance = instanceName + "-restored";
String clusterName = TestFixtures.uniqueName("rds-pitr-cluster");
String restoredCluster = clusterName + "-restored";
try {
createDbInstance(rds, instanceName, "pitr-secret");
DBInstance source = rds.describeDBInstances(b -> b.dbInstanceIdentifier(instanceName))
.dbInstances().get(0);
assertThat(source.latestRestorableTime()).isNotNull();
DBInstance restored = rds.restoreDBInstanceToPointInTime(b -> b
.sourceDBInstanceIdentifier(instanceName)
.targetDBInstanceIdentifier(restoredInstance)
.useLatestRestorableTime(true)
.dbInstanceClass("db.t3.small"))
.dbInstance();
assertThat(restored.dbInstanceIdentifier()).isEqualTo(restoredInstance);
assertThat(restored.dbInstanceClass()).isEqualTo("db.t3.small");
assertThat(restored.dbName()).isEqualTo("app");
assertThatThrownBy(() -> rds.restoreDBInstanceToPointInTime(b -> b
.sourceDBInstanceIdentifier(instanceName)
.targetDBInstanceIdentifier(instanceName + "-early")
// Before the source existed, so outside its restorable window.
.restoreTime(Instant.now().minusSeconds(3 * 86400))))
.isInstanceOf(InvalidRestoreException.class);
rds.createDBCluster(b -> b
.dbClusterIdentifier(clusterName)
.engine("aurora-postgresql")
.engineVersion("16.3")
.masterUsername("admin")
.masterUserPassword("pitr-secret")
.databaseName("app"));
DBCluster sourceCluster = rds.describeDBClusters(b -> b.dbClusterIdentifier(clusterName))
.dbClusters().get(0);
assertThat(sourceCluster.earliestRestorableTime()).isNotNull();
assertThat(sourceCluster.latestRestorableTime()).isAfterOrEqualTo(sourceCluster.earliestRestorableTime());
DBCluster restoredFromTime = rds.restoreDBClusterToPointInTime(b -> b
.dbClusterIdentifier(restoredCluster)
.sourceDBClusterIdentifier(sourceCluster.dbClusterArn())
.restoreToTime(sourceCluster.earliestRestorableTime())
.restoreType("copy-on-write"))
.dbCluster();
assertThat(restoredFromTime.dbClusterIdentifier()).isEqualTo(restoredCluster);
assertThat(restoredFromTime.databaseName()).isEqualTo("app");
} finally {
deleteDbInstance(rds, restoredInstance);
deleteDbInstance(rds, instanceName);
for (String name : List.of(restoredCluster, clusterName)) {
try {
rds.deleteDBCluster(b -> b.dbClusterIdentifier(name).skipFinalSnapshot(true));
} catch (Exception e) {
LOG.log(Level.WARNING, "Failed to clean up RDS cluster " + name, e);
}
}
}
}
private static CreateDbProxyResponse createIamProxy(RdsClient client, String name, List<String> vpcSubnetIds) {
return client.createDBProxy(b -> b
.dbProxyName(name)