Example usage for com.amazonaws.services.rds AmazonRDSClient createDBSnapshot

List of usage examples for com.amazonaws.services.rds AmazonRDSClient createDBSnapshot

Introduction

In this page you can find the example usage for com.amazonaws.services.rds AmazonRDSClient createDBSnapshot.

Prototype

@Override
public DBSnapshot createDBSnapshot(CreateDBSnapshotRequest request) 

Source Link

Document

Creates a DBSnapshot.

Usage

From source file:br.com.objectos.aws.rds.maven.plugin.CreateSnapshotMojo.java

License:Apache License

private void execute0() throws MojoExecutionException {
    AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
    AmazonRDSClient client = new AmazonRDSClient(credentials);

    CreateDBSnapshotRequest createDBSnapshotRequest = new CreateDBSnapshotRequest()
            .withDBInstanceIdentifier(dBInstanceIdentifier).withDBSnapshotIdentifier(dBSnapshotIdentifier);

    info("Starting RDS Snapshot '%s' at '%s'", dBSnapshotIdentifier, dBInstanceIdentifier);
    long startTime = System.currentTimeMillis();

    DBSnapshot snapshot = client.createDBSnapshot(createDBSnapshotRequest);
    info("Backing up... please wait.");

    while (!isDone(snapshot)) {
        try {//  w  w  w.  j  a v  a2 s.c  om
            Thread.sleep(5000);
            snapshot = describeSnapshot(client);

            if (snapshot == null) {
                break;
            }
        } catch (InterruptedException e) {
            throw new MojoExecutionException("Interrupted while waiting", e);
        }
    }

    long endTime = System.currentTimeMillis();

    info("Snapshot took %d ms", endTime - startTime);
}