Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
270 views
in Technique[技术] by (71.8m points)

amazon web services - AWS - RDS - Restoring database from snapshot everyday

I wonder if It is possible to restore database on AWS from snapshot everyday in specific time? I'm not meaning creating new instance, just restoring database to have default data.

I need this becouse I wrote some Django app and put her on Heroku. People can add there some records and making some kind of mess. I want restore database everyday to "clean" site from unecessery data everyday.

Thanks


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There's nothing stopping you from doing that.

I'd build it the following way:

  1. Create a CNAME record to point to the DNS record of the current database instance
  2. Reference that CNAME in your application
  3. Create a lambda that triggers daily
  4. Use that Lambda to create a new database instance from the known-good snapshot
  5. Afterwards the lambda should update the CNAME record from 1) to point to the new instance
  6. Then delete the old instance without making a final snapshot

You can leverage AWS Step Functions to orchestrate 4-6, because database operations take time and lambda runtime is finite.

Alternatively you can export the known good state of the DB as an SQL statement (research: sqldump) and then write a lambda function that gets triggered once per day, drops the old schema and creates a new schema from the known-good dump.

If the database is small, I'd go with the second alternative. For larger ones, I'd probably stick with the first. Beware that the second one will have a brief period where the application doesn't have access to a functioning database.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...