Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Aurora: how to restore a db cluster snapshot via aws cli?

It's pretty easy via the console but I need to do the same from CLI.

First I created a db snapshot:

aws rds create-db-cluster-snapshot \
    --db-cluster-snapshot-identifier $SNAPSHOT_ID \
    --db-cluster-identifier $CLUSTER \

CLUSTER contains only one writer instance

I did not use create-db-snapshot method because it throwned an error

A client error (InvalidParameterValue) occurred when calling the CreateDBSnapshot operation: The specified instance is a member of a cluster and a snapshot cannot be created directly. Please use the CreateDBClusterSnapshot API instead.

It works:

aws rds create-db-cluster-snapshot \
  --db-cluster-snapshot-identifier $SNAPSHOT_ID \
  --db-cluster-identifier $CLUSTER \
{
    "DBClusterSnapshot": {
        "Engine": "aurora", 
        "SnapshotCreateTime": "2016-12-08T11:48:07.534Z", 
    ....
}

So, I wanted to restore a new Aurora cluster from the snapshot, then I tried:

aws rds restore-db-instance-from-db-snapshot \
    --db-instance-identifier from-snap2 \
    --db-snapshot-identifier snap2 \

 A client error (DBSnapshotNotFound) occurred when calling the RestoreDBInstanceFromDBSnapshot operation: DBSnapshot not found: snap2

So I tried to restore with:

aws rds restore-db-cluster-from-snapshot \
    --db-cluster-identifier from-snap2 \
    --snapshot-identifier snap2 \
    --engine aurora \
    --vpc-security-group-ids $PREPROD_SG \
    --db-subnet-group-name my-db-subnet-group \

It works...

{
    "DBCluster": {
        ...
        "EngineVersion": "5.6.10a", 
        "DBClusterIdentifier": "from-snap2", 
...
        "DBClusterMembers": [], 
...
}

But why the cluster does not contain any Aurora instance?

Where is the mistake?

like image 668
Benoit Mariaux Avatar asked Dec 08 '16 12:12

Benoit Mariaux


People also ask

How do I restore an RDS snapshot to an existing instance?

Sign in to the AWS Management Console and open the Amazon RDS console at https://console.aws.amazon.com/rds/ . In the navigation pane, choose Snapshots. Choose the DB snapshot that you want to restore from. For Actions, choose Restore snapshot.

How do you restore an Aurora?

You can recover your data by creating a new Aurora DB cluster from the backup data that Aurora retains, or from a DB cluster snapshot that you have saved. You can quickly restore a new copy of a DB cluster created from backup data to any point in time during your backup retention period.


3 Answers

This is very counterintuitive. If you restore a cluster from a snapshot, but there are no member instances in the cluster, what operation has actually succeeded? It seems as if all this does is create some kind of logical entity, maybe the backing store, but no instances.

Strange. But, the API documentation does show the cluster members as an empty set in the example response.

<DBClusterMembers/>

So it seems you create a cluster, as you did, then you apparently create instances in the cluster, as explained in an AWS Forum post:

aws rds create-db-instance --db-instance-identifier my-instance --db-instance-class db.r3.large --engine aurora --db-subnet-group-name default-vpc-xxxxxx --db-cluster-identifier my-instance-cluster

https://forums.aws.amazon.com/thread.jspa?messageID=688727

Apparently the console encapsulates multiple API requests behind the same action.

like image 101
Michael - sqlbot Avatar answered Sep 20 '22 17:09

Michael - sqlbot


Response from AWS Support:

This is a known issue when using the API calls and our engineers are working on it. Even if the cluster is visible on AWS Console after the creation via CLI it will not create any instance automatically in your Aurora Cluster. In this case, you will need to create a db-instance and associate it to your newly restored cluster. When performing this Action on the AWS Console a new instance is automatically created for the cluster, but the action from the CLI uses separated API calls.

The following documentation provides detailed information on how to create a DB instance: http://docs.aws.amazon.com/cli/latest/reference/rds/create-db-instance.html

You can describe your clusters using the AWS Console or using the CLI: http://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-clusters.html

Here is a command line example that creates the instance and associate it to a fictional cluster: aws rds create-db-instance --engine aurora --db-cluster-identifier yourauroraclusteridentifier --db-instance-class db.t2.medium --db-instance-identifier yourinstanceidentifier

In my case, --db-cluster-identifier is the cluster created from the cluster snapshot.

like image 22
Benoit Mariaux Avatar answered Sep 20 '22 17:09

Benoit Mariaux


If you create with aws rds create-db-cluster-snapshot then you can't restore with aws rds restore-db-instance-from-db-snapshot. The first creates a DB snapshot and the second restores a Cluster snapshot, different types.

From your question it looks like your restore is correct, maybe you need --database-name specified. Also you could try the restore with only the required parameters, i.e no vpc sg or DB subnet.

like image 39
NHol Avatar answered Sep 20 '22 17:09

NHol