AmazonRDS: 将快照还原到现有实例

我已经创建了实例的快照,并在 DB 中做了一些不必要的更改。

现在我要从这个快照中恢复我的实例。

当我尝试这样做的时候,它创建了另一个实例,除了我已经有的实例之外。

我指定“ DB 实例标识符”,然后我得到两个具有相同 ID 的实例。

所以我的问题是: 有没有办法将快照恢复到现有的实例?

因为在其他情况下——新实例是用不同的端点(主机名)创建的,我需要更改配置来访问数据库。或者有更好的办法来处理这类案件?

62303 次浏览

No you can't restore back your existing DB instance to any of the either manual backup or point-in-time snapshot.

The only way you can make use of the manual backup or automated snapshot is to create a new RDS DB instance using that. Once the new DB instance is created, you can change the endpoint of DB in your app / code and delete the old DB instance.

Bottomline : You have to change the config settings in your app. No other option.

I had the same issue today. I think you have two options without changing the application's configuration setting.

  1. delete the old instance as Mike suggested, then restore it.

  2. rename the old instance first ( need to check "Apply immediately" option when rename it).

If anyone came here (just like me) to just restore data without altering your configuration.

Here are the steps :

  • Create a new instance(temp) from your automatic snapshots or manually created ones.
  • Connect to this instance from either Sequel pro or Mysql workbench.
  • Take SQL dump of whatever data you needed from this temp instance.
  • Connect your production instance and restore it.
  • Now delete the temp instance you created.

Rename original instance and name new instance with original name

https://aws.amazon.com/blogs/aws/endpoint-renaming-for-amazon-rds/

As @MaXimus said (I cannot add comments yet) you can:

  1. rename original instance first
  2. restore from snapshot and assign original instance name

As it's specified in Renaming to Replace an Existing DB Instance here: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_RenameInstance.html

After you created the restored db with a new name you can rename the current instance to ...-old, this also renames the db url. After the url is also changed, you have to rename the restored db to the befored used name, wait until the url of the db changes. Then you have to restart your services, and they will connect to the restored db.

This causes no outage at all.

Solution if you want to run through AWS CLI. Replace ORIG_NAME and NEW_NAME with your values

$ aws rds modify-db-instance \
--db-instance-identifier ORIG_NAME \
--new-db-instance-identifier NEW_NAME \
--apply-immediately


$ aws rds restore-db-instance-to-point-in-time \
--source-db-instance-identifier NEW_NAME \
--target-db-instance ORIG_NAME \
--restore-time 2020-08-27T00:00:00.000Z \
--publicly-accessible \
--availability-zone us-east-2a \
--db-subnet-group-name SUBNET_NAME \
--vpc-security-group-ids SG_ID


  • If you don't have a custom VPC, you can skip --db-subnet-group-name
  • If you don't have a custom security group for your RDS, you can skip --vpc-security-group-ids
  • If you don't need public access to your instance skip --publicly-accessible

So a short version of the aws rds restore-db-instance-to-point-in-time then would be:

$ aws rds restore-db-instance-to-point-in-time \
--source-db-instance-identifier NEW_NAME \
--target-db-instance ORIG_NAME \
--restore-time 2020-08-27T00:00:00.000Z