Blog

Replicating AWS RDS automated backups to a different region

30 Mar, 2022
Xebia Background Header Wave

Not so long ago AWS added support for automated backups replication. This gives us the ability to set up automatic replication of system snapshots and transaction logs from a primary AWS Region to a secondary AWS Region of your choice.
This feature is actually very useful when it comes to database disaster-recovery, we can easily restore a database instance from the replicated backups in our fail-over region.
Prior to cross-region automated backups, building a cost effective cross-region disaster recovery solution involved custom scripts or a AWS Lambda function to create a database snapshot, copy the snapshot to a different region and restore a new database instance from the copied snapshot. That’s no longer the case, this new disaster recovery capability utilizes the existing RDS backup functionality to set up automatic replication of system snapshots and transaction logs from a primary region to a secondary region.
cross region automated rds backups cross region replication 3 900x599 1
If you enable cross-region automated backups on your RDS DB instance, RDS creates a snapshot every day during the preferred backup window. In addition, it captures transaction logs to S3 every 5 minutes.

Implementing it through Terraform

In the upcoming v4.9.0 release of the Terraform AWS provider we introduced a new resource: aws_db_instance_automated_backups_replication.
Note that you should declare this resource in the target region that you want your automated backups to end up in.

Usage example

The resource schema is very straightforward, to replicate automated backups that are not encrypted use:

resource "aws_db_instance_automated_backups_replication" "default" {
  source_db_instance_arn = "arn:aws:rds:us-west-2:123456789012:db:mydatabase"
  retention_period       = 14
}

Ideally our backup volumes are encrypted using KMS, in that case we have to add the kms_key_id attribute:

resource "aws_kms_key" "default" {
  description = "Encryption key for automated backups"
}

resource "aws_db_instance_automated_backups_replication" "default" {
  source_db_instance_arn = "arn:aws:rds:us-west-2:123456789012:db:mydatabase"
  kms_key_id             = aws_kms_key.default.arn
  retention_period       = 14
}

The take away

Cross-region automated backups replication is a cost-effective strategy that helps save on compute costs. This feature significantly reduces management overhead, enabling database administrators to focus on other tasks.
Before implementing automated backups replication please be aware of the limitations and considerations. See the RDS User Guide for more information on this.

Bruno Schaatsbergen
Bruno is an open-source and serverless enthusiast. He tends to enjoy looking for new challenges and building large scale solutions in the cloud. If he's not busy with cloud-native architecture/development, he's high-likely working on a new article or podcast covering similar topics. In his spare time he fusses around on Github or is busy drinking coffee and exploring the field of cosmology.
Questions?

Get in touch with us to learn more about the subject and related solutions

Explore related posts