DEV Community

Cover image for How-to setup a HA/DR database in AWS? [6 - Create from snapshot]
Maxime Guilbert
Maxime Guilbert

Posted on • Updated on

How-to setup a HA/DR database in AWS? [6 - Create from snapshot]

In this post we will see how to create an AWS RDS Global database from a snapshot.


Why create a database from a snapshot if we already have the DR?

For sure, if you have a DR system, you might be have to create your global database from a snapshot every day (I hope for you so).

But when you are delivering a huge update on your database, you maybe want to have something to go back to the last state before, or if you are migrating data from a database to another.


How to create a global database from a snapshot ?

If you have checked the documentation, you have seen a parameter called snapshot_identifier in the aws_rds_cluster definition.

If you define a value here and run your script, you will have all the elements created but the cluster with the snapshot won't be linked to the global database.

In the solution presented in the last post, we did :
1 - the creation of the global cluster
2 - then we create the principal cluster
3 - and then we create all the other clusters

But to make it work, we need to change this order and the links.

We need to create first the principal cluster from the snapshot, without links to the global database.

This one

global_cluster_identifier = aws_rds_global_cluster.example.id
Enter fullscreen mode Exit fullscreen mode

Then, we have to create the global cluster. But this time, we will say to the global cluster that it needs to be based on the primary cluster.

resource "aws_rds_global_cluster" "example" {
  global_cluster_identifier = "global-test"

  source_db_cluster_identifier = aws_rds_cluster.default.arn
  force_destroy = true
}
Enter fullscreen mode Exit fullscreen mode

In this global cluster definition, we can see that a lot of parameters desapeared (like engine, database name...) and it's because the global cluster will take the configurations of the primary cluster!

Note : If you are creating a cluster from a snapshot, the master_username won't be override by the one you defined in your script, it will keep the one defined in the snapshot, but master_username yes.


I hope it will help you! 🍺

And see you soon for the next part of this serie. 😀


Serie link


You want to support me?

Buy Me A Coffee

Top comments (0)