A Fader Darkly
A Fader Darkly

Reputation: 3626

How do I copy a Postgres database from one Elastic Beanstalk environment to another? I'm using Rails 5

I have a pair of Elastic Beanstalk environments, called "development" and "production". I would like to copy the data from the "production" environment to "development", in order to have sensible data to test and work with.

Each environment is running a Rails 5 project (with a near-identical code base) and has an "associated" RDS instance.

I have tried looking in the AWS console, but I can only find an option to restore from a snapshot on the same database. (I could easily be missing something, the console is complex.)

I also tried updating the Postgres tools (to 9.6) on the web server instances so I could use pg_dump and pg_restore. However, the operation fails as there are two current connections (I tried rake db:drop in this case, but I assume a more direct approach using psql would give the same issue).

Is there another way to copy the database over, or can I safely kill the connections in order to carry out the restore? If so, how?

Upvotes: 2

Views: 442

Answers (1)

Mark B
Mark B

Reputation: 200436

I can only find an option to restore from a snapshot on the same database

You are misunderstanding how restores work in RDS. When you restore a snapshot it always creates an entirely new RDS instance from the snapshot. To do what you are asking you would first create an RDS snapshot of the database you want to copy, then restore that snapshot, which will create a new RDS instance. Then you would point your EB environment to the new RDS instance. Finally delete the old RDS instance that is no longer in use.

Upvotes: 2

Related Questions