DevOps Hive

Patterns / Recover

Copy AWS backups to another region and restore from them

A backup plan that copies every daily recovery point to a vault in a second region, so your data survives the loss of the region you run in. It covers the data only, and the steps say what else a restore needs.

  1. Tagged resource
  2. Primary vault
  3. Copy job
  4. Second region vault
  5. Restore

How it works

  1. What a backup in the same region does not protect

    Backups stored next to the database protect you from a bad deploy or a deleted table. They do not help if the whole region is unavailable, or if the account's resources in that region are damaged. A copy in a second region is a separate set of data that does not depend on the first.

  2. Create a vault in each region

    The configuration uses two provider blocks, one per region, and creates a vault in each. The copy vault is encrypted with a key that belongs to the second region. Choose a second region far from the first, and check that any rules on where your data may be stored allow it.

  3. Add a copy action to the daily rule

    The plan backs up every resource tagged backup = daily, then copies the new recovery point to the second vault. The copy starts after the backup finishes and can take from minutes to hours for a large database. Copies are kept for 14 days by default, because they are billed as storage in the second region.

  4. How a restore in the second region works

    Open the copy vault in the second region, pick a recovery point and start a restore with the backup role. This creates a new database in that region. It needs a VPC, a database subnet group and a security group there, and if those do not exist the restore cannot start. Build that network ahead of time.

  5. What is not covered

    This copies data and nothing else. Your application, its container images, its settings and passwords, DNS records and load balancers are not in the vault and have to be created in the second region some other way. Anything written after the last backup is lost, which can be up to a day of data. Resources without the tag are not copied at all.

  6. Run a restore drill

    The mistake people make is assuming the copies work because the copy jobs succeed. Restore one recovery point in the second region, connect to the new database and check the data is there, then delete it. Write down how long it took and what you had to create by hand.

What you set

primary_region
Region where the resources to back up live For example us-east-1
copy_region
Second region that receives the copies For example us-west-2
backup_tag_value
Value of the backup tag that marks a resource For example daily
copy_retention_days
Days to keep each copy in the second region For example 14

What it costs to run

Driven by GB stored in two regions plus a per GB charge for moving each copy between regions. For one database of around 20 GB, expect roughly 5 to 20 dollars a month. Restoring a database for a drill is billed as a running database for as long as you keep it. Estimate.

The configuration

# Daily backups that are also copied to a second AWS region.
#
# What this creates:
#   - a backup vault in your primary region and another in a second region
#   - a plan that backs up tagged resources daily and copies each recovery
#     point to the second region
#   - the IAM role AWS Backup uses to back up, copy and restore
#
# What this does NOT create: anything to restore into. The second region needs
# its own network, and your application has to be deployed there, before a
# restored database is of any use. See the steps that go with this pattern.

terraform {
  required_version = ">= 1.6.0"
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}

# Two providers: one for the region you run in, one for the region that holds
# the copies.
provider "aws" {
  region = var.primary_region
}

provider "aws" {
  alias  = "copy"
  region = var.copy_region
}

variable "primary_region" {
  description = "AWS region where the resources to back up live."
  type        = string
  default     = "us-east-1"
}

variable "copy_region" {
  description = "Second AWS region that receives a copy of every recovery point. Pick one far enough away that one event cannot affect both."
  type        = string
  default     = "us-west-2"
}

variable "name" {
  description = "Short name used for the vaults, plan and role."
  type        = string
  default     = "cross-region"
}

variable "backup_tag_key" {
  description = "Tag key that marks a resource for backup."
  type        = string
  default     = "backup"
}

variable "backup_tag_value" {
  description = "Tag value that marks a resource for backup."
  type        = string
  default     = "daily"
}

variable "schedule" {
  description = "When the backup runs, as a cron expression in UTC. The default is 05:00 UTC every day."
  type        = string
  default     = "cron(0 5 * * ? *)"
}

variable "retention_days" {
  description = "Days to keep each recovery point in the primary region."
  type        = number
  default     = 35
}

variable "copy_retention_days" {
  description = "Days to keep each copy in the second region. Copies are billed as storage there, so a shorter period costs less."
  type        = number
  default     = 14
}

resource "aws_backup_vault" "primary" {
  name = "${var.name}-primary"

  # With force_destroy off, deleting a vault that still holds recovery points
  # fails. To tear down a test, set this to true on both vaults, apply, then
  # destroy.
  force_destroy = false
}

# The copy vault is encrypted with a key that lives in the second region, so
# the copies do not depend on anything in the primary region.
resource "aws_backup_vault" "copy" {
  provider = aws.copy
  name     = "${var.name}-copy"

  force_destroy = false
}

data "aws_iam_policy_document" "assume" {
  statement {
    effect  = "Allow"
    actions = ["sts:AssumeRole"]

    # Only the AWS Backup service can use this role.
    principals {
      type        = "Service"
      identifiers = ["backup.amazonaws.com"]
    }
  }
}

# IAM is global, so the same role works for restores in either region.
resource "aws_iam_role" "backup" {
  name               = "${var.name}-aws-backup"
  assume_role_policy = data.aws_iam_policy_document.assume.json
}

resource "aws_iam_role_policy_attachment" "backup" {
  role       = aws_iam_role.backup.name
  policy_arn = "arn:aws:iam::aws:policy/service-role/AWSBackupServiceRolePolicyForBackup"
}

resource "aws_iam_role_policy_attachment" "restore" {
  role       = aws_iam_role.backup.name
  policy_arn = "arn:aws:iam::aws:policy/service-role/AWSBackupServiceRolePolicyForRestores"
}

resource "aws_backup_plan" "this" {
  name = var.name

  rule {
    rule_name         = "daily-with-copy"
    target_vault_name = aws_backup_vault.primary.name
    schedule          = var.schedule
    start_window      = 60
    completion_window = 360

    lifecycle {
      delete_after = var.retention_days
    }

    # The copy starts when the backup finishes, so the second region is always
    # a little behind the first.
    copy_action {
      destination_vault_arn = aws_backup_vault.copy.arn

      lifecycle {
        delete_after = var.copy_retention_days
      }
    }
  }
}

# Every resource AWS Backup supports that carries the tag is included. A
# resource without the tag is not backed up and not copied.
resource "aws_backup_selection" "tagged" {
  name         = "tagged-${var.backup_tag_value}"
  plan_id      = aws_backup_plan.this.id
  iam_role_arn = aws_iam_role.backup.arn
  resources    = ["*"]

  selection_tag {
    type  = "STRINGEQUALS"
    key   = var.backup_tag_key
    value = var.backup_tag_value
  }

  # The role needs its policies before the first job runs.
  depends_on = [
    aws_iam_role_policy_attachment.backup,
    aws_iam_role_policy_attachment.restore,
  ]
}

output "primary_vault_name" {
  description = "Vault in the primary region."
  value       = aws_backup_vault.primary.name
}

output "copy_vault_name" {
  description = "Vault in the second region. Start a cross-region restore from here."
  value       = aws_backup_vault.copy.name
}

output "copy_vault_arn" {
  description = "ARN of the vault in the second region."
  value       = aws_backup_vault.copy.arn
}

output "backup_role_arn" {
  description = "Role AWS Backup uses. Choose it when you start a restore in either region."
  value       = aws_iam_role.backup.arn
}

Works with OpenTofu 1.6 or later, and with Terraform. Read it before you apply it: it creates real resources in your account.

Written by DevOps Hive. Last updated 2026-11-27.

More in recover