Home > Enterprise >  How to repeatedly restore AWS RDS database to the initial state after running tests
How to repeatedly restore AWS RDS database to the initial state after running tests

Time:12-08

I'm using AWS RDS Aurora Postgres 12.9.

I have a database in an "initial state" with some data on it, I want to insert/update many data on it, and then easily restore it to the "initial state" whenever I want.

For example, the solution could also be applicable to use in integration tests that uses a real database.

I'm restoring a snapshot but this takes to much time. See https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_RestoreFromSnapshot.html

Expectation:

  • I'm OK to losse all changes after restoring to "initial state".
  • I may want to repeat this process a few times.
  • As less time I spend restoring to "initial state" as better, but It's OK to take just a few minutes.
  • Many people may want to access and manipulate data on it.

Scenario:

Setup a RDS database in "initial state" 1 - Spend some minutes manipulating many data on it. 2 - Spend some minutes analyzing the new state. 3 - Restore to "initial state" and repeat steps 1, 2, 3 without waiting to much.

Thank you.

CodePudding user response:

You could do this, but it's not the right way to approach testing. In general, external systems like a database should be integrated using an adapter which you can stub out to return mock responses (which could be your "initial state"). In terms of sharing access to mocks, you generally don't need to: anyone who needs to access the datastore can run the same mock setup you do and therefore share the same state, without sharing an actual instance.

CodePudding user response:

I'm going to use the RDS "clone", see https://aws.amazon.com/blogs/aws/amazon-aurora-fast-database-cloning/

That way I can get a clone in about 5 minutes ready to manipulate data on it, with no side effects on the original instance.

  • Related