Aracılığıyla paylaş


Hızlı Başlangıç: Azure Resource Manager şablonuyla PostgreSQL için Azure Veritabanı - Esnek Sunucu için yedeklemeyi yapılandırma

Bu hızlı başlangıçta, Azure Resource Manager şablonuyla PostgreSQL için Azure Veritabanı - Esnek Sunucu için yedeklemenin nasıl yapılandırıldığı açıklanmaktadır.

Azure Backup , Azure portal, PowerShell, CLI, Azure Resource Manager, Bicep gibi birden çok istemci kullanarak Azure PostgreSQL - Esnek Sunucunuzu yedeklemenize olanak tanır. Bu makale, Bir Yedekleme kasası oluşturmak ve ardından Azure PostgreSQL - Esnek Sunucu için yedeklemeyi yapılandırmak üzere bir Azure Resource Manager (ARM) şablonu dağıtma işlemine odaklanır. ARM şablonları geliştirme hakkında daha fazla bilgi edinin.

Azure Resource Manager şablonu, projenizin altyapısını ve yapılandırmasını tanımlayan bir JavaScript Nesne Gösterimi (JSON) dosyasıdır. Şablon deklaratif sözdizimini kullanır. Dağıtımı oluşturmak için programlama komutlarının sırasını yazmadan hedeflenen dağıtımınızı açıklarsınız.

Önkoşullar

Ortamınızı Bicep geliştirme için ayarlamak adına, Bicep araçlarını yükleme bölümüne bakın.

Note

Makalede ayrıntılı olarak açıklandığı gibi en son Azure PowerShell modülünü ve Bicep CLI'yi yükleyin.

Şablonu gözden geçirme

Bu şablon, Azure PostgreSQL - Esnek sunucu için yedekleme yapılandırmanızı sağlar. Bu şablonda postgreSQL sunucusu için haftalık zamanlamaya ve üç aylık saklama süresine sahip bir yedekleme ilkesine sahip bir yedekleme kasası oluşturacağız.

{
  "$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": [
          "Microsoft.DBforPostgreSQL/flexibleServers"
        ],
        "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": "Microsoft.DBforPostgreSQL/flexibleServers",
          "objectType": "Datasource",
          "resourceId": "[resourceId(parameters('postgreSQLResourceGroup'), 'Microsoft.DBforPostgreSQL/flexibleServers', parameters('postgreSQLServerName'))]"
        },
        "policyInfo": {
          "policyId": "[resourceId(parameters('backupVaultResourceGroup'), 'Microsoft.DataProtection/backupVaults/backupPolicies', parameters('backupVaultName'), parameters('policyName'))]"
        }
      }
    }
  ]
}

Şablonu dağıtma

Şablonu dağıtmak için, şablonu bir GitHub deposunda depolayın ve ardından aşağıdaki PowerShell betiğini kabuk penceresine yapıştırın.

$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 

Sonraki adımlar

Azure PowerShellkullanarak PostgreSQL için Azure Veritabanı - Esnek sunucuyu geri yükleyin.