You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Terraform配置Azure SQL数据库的区域冗余备份存储冗余

Azure SQL 区域冗余备份存储 Terraform 配置方法

你现有配置中的zone_redundant参数控制数据库实例是否跨可用区部署,storage_account_type参数控制数据库本身的存储冗余类型,备份存储的冗余规则需要单独配置专属参数实现。

具体配置说明

在azurerm_mssql_database资源中新增backup_storage_redundancy参数,设置为Zone即可启用区域冗余备份存储,参数可选值如下:

  • Local:本地冗余备份
  • Zone:区域冗余备份
  • Geo:异地冗余备份(默认值)
  • GeoZone:跨区域+区域冗余备份

注意事项

  • 需使用3.0及以上版本的azurerm Provider,低于该版本需先升级Provider版本
  • 仅部分数据库SKU和Azure区域支持区域冗余备份,部署前需确认对应SKU在目标区域的支持性
  • 若需配置长期保留备份(LTR)的冗余规则,需在azurerm_mssql_database_long_term_retention_policy资源中单独设置storage_account_type为ZRS

修改后的完整配置示例

resource "azurerm_mssql_server" "ms" {
  name                         = lower(var.server_name)
  resource_group_name          = var.resource_group_name
  location                     = var.location
  version                      = var.server_version
  administrator_login          = var.admin_login
  administrator_login_password = var.admin_password
  connection_policy            = var.sql_server_connection_policy
  tags                         = var.tags
}

resource "azurerm_mssql_database" "md" {
  name           = var.database_name
  server_id      = azurerm_mssql_server.ms.id
  max_size_gb    = 250
  read_scale     = false
  zone_redundant = true
  storage_account_type = "ZRS"
  # 新增区域冗余备份配置
  backup_storage_redundancy = "Zone"

  threat_detection_policy {
    state = "Enabled"
  }
}

resource "azurerm_private_endpoint" "pe" {
  name                = var.private_endpoint_name 
  location            = var.location
  resource_group_name = var.resource_group_name
  subnet_id           = azurerm_subnet.subnet.id

  private_service_connection {
    name                           = var.private_service_connection_name 
    private_connection_resource_id = azurerm_mssql_server.ms.id
    is_manual_connection           = false
    subresource_names              = ["sqlServer"]
  }
}

配置验证

部署完成后可在Azure门户对应SQL数据库的「备份」页面,查看存储冗余配置是否为区域冗余,确认配置生效。

内容的提问来源于stack exchange,提问作者Daniel Vega Ruiz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 04:24:05