共用方式為


備份 Azure PostgreSQL - 具有 Azure Resource Manager 範本的彈性伺服器 (預覽)

Azure 備份 可讓您使用多個選項來備份 Azure PostgreSQL - 彈性伺服器,例如 Azure 入口網站、PowerShell、CLI、Azure Resource Manager、Bicep 等等。 本文說明如何使用 Azure Resource Manager 範本和 Azure PowerShell 來備份 Azure PostgreSQL - 彈性伺服器。 本快速入門著重於部署 Azure Resource Manager (ARM) 範本以建立備份保存庫的程式,然後設定 Azure PostgreSQL - 彈性伺服器的備份。 如需開發 ARM 範本的詳細資訊,請參閱 Azure Resource Manager 檔

Azure Resource Manager 範本是一個 JavaScript 物件標記法 (JSON) 檔案,會定義專案的基礎結構和設定。 範本使用宣告式語法。 您可以描述預期的部署,而不需要撰寫程式設計命令順序來建立部署。

必要條件

若要設定您的環境以進行 Bicep 開發,請參閱安裝 Bicep 工具 (部分機器翻譯)。

注意

如文章所詳述,安裝最新 Azure PowerShell 模組和 Bicep CLI。

檢閱範本

此範本可讓您設定 Azure PostgreSQL - 彈性伺服器的備份。 在此範本中,我們會使用每周排程和三個月的保留期間,建立具有 PostgreSQL 伺服器的備份原則備份保存庫。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "backupVaultName": {
      "type": "string"
    },
    "backupVaultResourceGroup": {
      "type": "string"
    },
    "postgreSQLServerName": {
      "type": "string"
    },
    "postgreSQLResourceGroup": {
      "type": "string"
    },
    "region": {
      "type": "string"
    },
    "policyName": {
      "type": "string"
    },
    "backupScheduleFrequency": {
      "type": "string"
    },
    "retentionDurationInMonths": {
      "type": "int"
    },
    "targetResourceGroupName": {
      "type": "string"
    }
  },
  "resources": [
    {
      "type": "Microsoft.DataProtection/backupVaults",
      "apiVersion": "2023-01-01",
      "name": "[parameters('backupVaultName')]",
      "location": "[parameters('region')]",
      "identity": {
        "type": "SystemAssigned"
      },
      "properties": {
        "storageSettings": [
          {
            "datastoreType": "VaultStore",
            "type": "LocallyRedundant"
          }
        ]
      }
    },
    {
      "type": "Microsoft.DataProtection/backupVaults/backupPolicies",
      "apiVersion": "2023-01-01",
      "name": "[concat(parameters('backupVaultName'), '/', parameters('policyName'))]",
      "location": "[parameters('region')]",
      "properties": {
        "datasourceTypes": [
          "AzureDatabaseForPostgreSQLFlexibleServer"
        ],
        "policyRules": [
          {
            "name": "BackupSchedule",
            "objectType": "AzureBackupRule",
            "backupParameters": {
              "objectType": "AzureBackupParams"
            },
            "trigger": {
              "schedule": {
                "recurrenceRule": {
                  "frequency": "Hourly",
                  "interval": "[parameters('backupScheduleFrequency')]"
                }
              }
            },
            "dataStore": {
              "datastoreType": "VaultStore"
            }
          },
          {
            "name": "RetentionRule",
            "objectType": "AzureRetentionRule",
            "isDefault": true,
            "lifecycle": {
              "deleteAfter": {
                "objectType": "AbsoluteDeleteOption",
                "duration": "[concat('P', parameters('retentionDurationInMonths'), 'M')]"
              }
            }
          }
        ]
      }
    },
    {
      "type": "Microsoft.Authorization/roleAssignments",
      "apiVersion": "2022-04-01",
      "name": "[guid(subscription().id, 'PostgreSQLFlexibleServerLongTermRetentionBackupRole
')]",
      "properties": {
        "principalId": "[reference(concat(resourceId(parameters('backupVaultResourceGroup'), 'Microsoft.DataProtection/backupVaults', parameters('backupVaultName')), '/providers/Microsoft.ManagedIdentity/Identities/default'), '2020-12-01').principalId]",
        "roleDefinitionId": "[subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e')]",
        "scope": "[resourceId(parameters('postgreSQLResourceGroup'), 'Microsoft.DBforPostgreSQL/flexibleServers', parameters('postgreSQLServerName'))]"
      }
    },
    {
      "type": "Microsoft.Authorization/roleAssignments",
      "apiVersion": "2022-04-01",
      "name": "[guid(subscription().id, 'Reader')]",
      "properties": {
        "principalId": "[reference(concat(resourceId(parameters('backupVaultResourceGroup'), 'Microsoft.DataProtection/backupVaults', parameters('backupVaultName')), '/providers/Microsoft.ManagedIdentity/Identities/default'), '2020-12-01').principalId]",
        "roleDefinitionId": "[subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e')]",
        "scope": "[resourceId(parameters('targetResourceGroupName'))]"
      }
    },
    {
      "type": "Microsoft.DataProtection/backupVaults/backupInstances",
      "apiVersion": "2023-01-01",
      "name": "PostgreSQLBackupInstance",
      "location": "[parameters('region')]",
      "properties": {
        "datasourceInfo": {
          "datasourceType": "AzureDatabaseForPostgreSQLFlexibleServer",
          "objectType": "Datasource",
          "resourceId": "[resourceId(parameters('postgreSQLResourceGroup'), 'Microsoft.DBforPostgreSQL/flexibleServers', parameters('postgreSQLServerName'))]"
        },
        "policyInfo": {
          "policyId": "[resourceId(parameters('backupVaultResourceGroup'), 'Microsoft.DataProtection/backupVaults/backupPolicies', parameters('backupVaultName'), parameters('policyName'))]"
        }
      }
    }
  ]
}

部署範本

若要部署範本,請將範本儲存在 GitHub 存放庫中,然後將下列 PowerShell 腳本貼到殼層視窗中。

$projectName = Read-Host -Prompt "Enter a project name (limited to eight characters) that is used to generate Azure resource names"
$location = Read-Host -Prompt "Enter the location (for example, centralus)"

$resourceGroupName = "${projectName}rg"
$templateUri = "https//templateuri"

New-AzResourceGroup -Name $resourceGroupName -Location $location
New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri $templateUri -projectName 

下一步