このクイック スタートでは、Azure Bicep ファイルを使用して Azure Database for PostgreSQL - フレキシブル サーバーのバックアップを構成する方法について説明します。
Azure Backup を使用すると、Azure portal、PowerShell、CLI、Azure Resource Manager、Bicep などの複数のクライアントを使用して、Azure PostgreSQL - フレキシブル サーバーをバックアップできます。 この記事では、Bicep ファイルをデプロイしてバックアップ コンテナーを作成し、Azure PostgreSQL - フレキシブル サーバーのバックアップを構成するプロセスについて説明します。 Bicep ファイルの開発について詳しくは、こちらをご覧ください。
Bicep は、Azure リソースを宣言によってデプロイするための言語です。 JSON の代わりに Bicep を使用して、Azure Resource Manager テンプレート (ARM テンプレート) を開発できます。 Bicep の構文により複雑さが軽減され、開発エクスペリエンスが向上します。 Bicep は ARM テンプレート JSON に対する透過的な抽象化であり、JSON テンプレートのすべての機能が提供されます。 デプロイ中に、Bicep CLI により、Bicep ファイルが ARM テンプレート JSON に変換されます。 Bicep ファイルでは、リソースを作成するための一連のプログラミング コマンドを記述せずに、Azure リソースとリソース プロパティを記述します。
ARM テンプレートで有効なリソースの種類、API バージョン、およびプロパティは、Bicep ファイルでも有効です。
前提条件
Bicep の開発環境を設定するには、「Bicep ツールをインストールする」を参照してください。
注記
記事で詳細に説明されているように、最新の Azure PowerShell モジュールと Bicep CLI をインストールします。
テンプレートを確認する
このテンプレートを使用すると、Azure PostgreSQL - フレキシブル サーバーのバックアップを構成できます。 このテンプレートでは、PostgreSQL サーバーのバックアップ ポリシーを含むバックアップ コンテナーを作成し、週ごとのスケジュールと、3 か月のリテンション期間を設定します。
@description('Specifies the name of the Backup Vault')
param backupVaultName string
@description('Specifies the name of the Resource group to which Backup Vault belongs')
param backupVaultResourceGroup string
@description('Specifies the name of the PostgreSQL server')
param postgreSQLServerName string
@description('Specifies the name of the Resource group to which PostgreSQL server belongs')
param postgreSQLResourceGroup string
@description('Specifies the region in which the Backup Vault is located')
param region string
@description('Specifies the name of the Backup Policy')
param policyName string
@description('Specifies the frequency of the backup schedule')
param backupScheduleFrequency string
@description('Specifies the retention duration in months')
param retentionDuration string
@description('Step 1: Create the Backup Vault')
resource backupVault 'Microsoft.DataProtection/backupVaults@2023-01-01' = {
name: backupVaultName
location: region
identity: {
type: 'SystemAssigned'
}
properties: {
storageSettings: [
{
datastoreType: 'VaultStore'
type: 'LocallyRedundant'
}
]
}
}
@description('Step 2: Create Backup Policy for PostgreSQL')
resource backupPolicy 'Microsoft.DataProtection/backupVaults/backupPolicies@2023-01-01' = {
name: '${backupVaultName}/${policyName}'
location: region
properties: {
datasourceTypes: [
'AzureDatabaseForPostgreSQLFlexibleServer'
]
policyRules: [
{
name: 'BackupSchedule'
objectType: 'AzureBackupRule'
backupParameters: {
objectType: 'AzureBackupParams'
}
trigger: {
schedule: {
recurrenceRule: {
frequency: 'Weekly'
interval: backupScheduleFrequency
}
}
}
dataStore: {
datastoreType: 'VaultStore'
}
}
{
name: 'RetentionRule'
objectType: 'AzureRetentionRule'
isDefault: true
lifecycle: {
deleteAfter: {
objectType: 'AbsoluteDeleteOption'
duration: 'P${retentionDuration}M'
}
}
}
]
}
}
@description('Step 3: Role Assignment for PostgreSQL Backup And Export Operator Role')
resource postgreSQLServer 'Microsoft.DBforPostgreSQL/flexibleServers@2022-03-01' existing = {
name: postgreSQLServerName
scope: resourceGroup(postgreSQLResourceGroup)
}
resource roleAssignmentBackupExportOperator 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid(backupVault.id, 'PostgreSQLFlexibleServerLongTermRetentionBackupRole')
properties: {
principalId: backupVault.identity.principalId
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e') // Role definition ID for 'PostgreSQL Backup And Export Operator'
scope: postgreSQLServer.id
}
}
@description('Step 4: Role Assignment for Reader on Resource Group')
resource targetResourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' existing = {
name: targetResourceGroupName
}
resource roleAssignmentReader 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid(backupVault.id, 'Reader')
properties: {
principalId: backupVault.identity.principalId
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '00aa00aa-bb11-cc22-dd33-44ee44ee44ee') // Role definition ID for 'Reader'
scope: targetResourceGroup.id
}
}
@description('Step 5: Create Backup Instance for PostgreSQL)
resource backupInstance 'Microsoft.DataProtection/backupVaults/backupInstances@2023-01-01' = {
name: 'PostgreSQLBackupInstance'
location: region
properties: {
datasourceInfo: {
datasourceType: 'AzureDatabaseForPostgreSQLFlexibleServer'
objectType: 'Datasource'
resourceId: postgreSQLServer.id
}
policyInfo: {
policyId: backupPolicy.id
}
}
}
テンプレートのデプロイ
このテンプレートをデプロイするには、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 = "templateURI"
New-AzResourceGroup -Name $resourceGroupName -Location $location
New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri $templateUri -projectName $projectName
次のステップ
Azure PowerShell を使用して Azure Database for PostgreSQL - フレキシブル サーバーを復元します。