How to Migrate Snapshot to an Existing Database in AWS RDS

amazon-rds

I currently have two databases, one for production environment and the other one for staging environment. I made snapshot of the production database to migrate it into the staging database.

I researched about how to do that, but most of resources explain making a new database from snapshot. In my case, I already hooked up the staging DB to my server, so I need to bring the snapshot directly into the staging server.

Can anyone explain how to do that?

Best Answer

It sounds as if you are trying to use a snapshot in a way it isn't intended to be used.

You don't load an RDS snapshot onto an existing system.

You use a snapshot to create a new system whose data is an exact duplicate of the system where the snapshot originated, at the time the snapshot was created.

In my case, I already hooked up the staging DB to my server, so I need to bring the snapshot directly into the staging server.

Rename the staging db you created, calling it something else. Then create a new instance from the snapshot, giving it the original name of the staging db. You should find that the new db instance has the same endpoint hostname that was assigned to your original one, and your staging environment connects to the new machine, though the app server might require a restart or reload to recognize the DNS changes that RDS takes care of in the background. If all goes well, delete the old staging instance.

Renaming to Replace an Existing DB Instance

The most common reasons for renaming a DB instance are that you are promoting a Read Replica or you are restoring data from a DB snapshot or PITR.

By renaming the database, you can replace the DB instance without having to change any application code that references the DB instance.

https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_RenameInstance.html

On the other hand, if you have multiple databases and you only want a subset captured from prod and cloned to stage, you won't use snapshots for this... you'll want to use standard administrative tools for your database family to extract data from prod and load onto stage.