티스토리 뷰

개발/AWS

AWS RDB 클러스터 복원

KyeongRok Kim 2018. 9. 4. 16:33

AWS RDB 클러스터 복원


AWS RDS SDK를 이용해 클러스터를 복원하는 명령어를 실행해서 클러스터를 복제 할 수 있다.


AWSConfiguration.java

1
2
3
4
5
6
7
8
9
10
11
12
13
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.services.rds.AmazonRDS;
import com.amazonaws.services.rds.AmazonRDSClientBuilder;
 
public class AWSConfiguration {
    public AmazonRDS amazonRDS() {
        return AmazonRDSClientBuilder
                .standard()
                .withCredentials(DefaultAWSCredentialsProviderChain.getInstance())
                .withRegion("us-west-2")
                .build();
    }
}
cs


RestoreClusterTest.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public class RestoreClusterTest {
    AmazonRDS amazonRDS = new AWSConfiguration().amazonRDS();
 
    @Test
    public void generateDbCluster() throws ParseException {
 
        RestoreDBClusterToPointInTimeRequest var1 = new RestoreDBClusterToPointInTimeRequest();
        var1.setDBClusterIdentifier("hello-krk-cluster-dev");
        var1.setDBSubnetGroupName("default");
        var1.setSourceDBClusterIdentifier("hello-server-dev-cluster");
 
        // 가장빠른 복원시간, 최근 복원시간 사이 값을 넣어준다.
        Date startDatetime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                .parse("2018-09-03 16:00:00");
        var1.setRestoreToTime(startDatetime);
 
        DBCluster cluster = amazonRDS.restoreDBClusterToPointInTime(var1);
        System.out.println(cluster.getDBClusterArn());
    }
}
cs


pom.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
 
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
 
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-core</artifactId>
            <version>${aws.sdk.version}</version>
        </dependency>
 
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-rds</artifactId>
            <version>${aws.sdk.version}</version>
        </dependency>
 
    </dependencies>
cs


728x90
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함