我正在使用 AWS Backup 拍摄多个 EC2 实例的快照,这些实例上都有多个标签。我已经验证,当拍摄快照时,这些标签会从正在运行的实例传播到快照。我希望能够在标签完好无损的情况下恢复这些快照。目前,它们不会传播到新恢复的实例,甚至实例的名称也留空。我正在使用 terraform 创建和管理备份。我了解恢复过程是手动的。以下是我的 terraform 代码供参考:
resource "aws_backup_region_settings" "legacy" {
resource_type_opt_in_preference = {
"Aurora" = false
"DynamoDB" = false
"EFS" = false
"FSx" = false
"RDS" = false
"Storage Gateway" = false
"EBS" = true
"EC2" = true
"DocumentDB" = false
"Neptune" = false
}
}
resource "aws_backup_vault" "legacy" {
name = "Legacy${var.environment_tag}"
kms_key_arn = aws_kms_key.mgn.arn
tags = merge(
local.tags, {
"Name" = "Legacy${var.environment_tag}"
}
)
}
resource "aws_iam_role" "legacy_backup" {
name = "AWSBackupService"
permissions_boundary = data.aws_iam_policy.role_permissions_boundary.arn
assume_role_policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Action": ["sts:AssumeRole"],
"Effect": "allow",
"Principal": {
"Service": ["backup.amazonaws.com"]
}
}
]
}
POLICY
}
resource "aws_iam_role_policy_attachment" "legacy_backup" {
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSBackupServiceRolePolicyForBackup"
role = aws_iam_role.legacy_backup.name
}
###############################################################################
##
## Weekly Backups
##
###############################################################################
resource "aws_backup_plan" "weekly" {
name = "Legacy${var.environment_tag}Weekly"
rule {
enable_continuous_backup = false
rule_name = "Legacy${var.environment_tag}Weekly"
target_vault_name = aws_backup_vault.legacy.name
schedule = var.backup_plan_weekly_schedule
start_window = 60 # minutes
completion_window = 180 # minutes
lifecycle {
cold_storage_after = 30 # days
delete_after = 120 # days
}
copy_action {
destination_vault_arn = aws_backup_vault.legacy.arn
lifecycle {
cold_storage_after = 30 # days
delete_after = 120 # days
}
}
copy_action {
destination_vault_arn = aws_backup_vault.secondary.arn
lifecycle {
cold_storage_after = 30 # days
delete_after = 120 # days
}
}
}
advanced_backup_setting {
backup_options = {
WindowsVSS = "enabled"
}
resource_type = "EC2"
}
tags = merge(
local.tags, {
"Name" = "Legacy${var.environment_tag}Weekly"
}
)
}
resource "aws_backup_selection" "weekly" {
iam_role_arn = aws_iam_role.legacy_backup.arn
name = "Legacy${var.environment_tag}Weekly"
plan_id = aws_backup_plan.weekly.id
selection_tag {
type = "STRINGEQUALS"
key = "AWSBackup"
value = "weekly"
}
}
有没有办法使用 terraform 和 aws_backup* 系列资源来解决这个问题,还是我需要使用其他工具,例如 lambda 来制作副本?