Quickstart: Restore Azure Database for PostgreSQL server across regions with PowerShell by using Azure Backup
This quickstart describes how to configure and perform cross-region restore for Azure Database for PostgreSQL server with Azure PowerShell.
Azure Backup allows you to back up and restore the Azure Database for PostgreSQL server. The Azure PowerShell AZ module allows you to create and manage Azure resources from the command line or in scripts. If you want to restore the PostgreSQL database across regions by using the Azure portal, see this Quickstart.
Enable Cross Region Restore for Backup vault
To enable the Cross Region Restore feature on the Backup vault that has Geo-redundant Storage enabled, run the following cmdlet:
Update-AzDataProtectionBackupVault -SubscriptionId $subscriptionId -ResourceGroupName $resourceGroupName -CrossRegionRestoreState $CrossRegionRestoreState
Note
You can't disable Cross Region Restore once protection has started with this feature enabled.
Configure restore for the PostgreSQL database to a secondary region
To restore the database to a secondary region after enabling Cross Region Restore, run the following cmdlets:
Fetch the backup instances from secondary region.
Search-AzDataProtectionBackupInstanceInAzGraph -Subscription $subscriptionId -ResourceGroup $resourceGroupName -Vault $vaultName -DatasourceType AzureDatabaseForPostgreSQL
Once you identify the backed-up instance, fetch the relevant recovery point by using the
Get-AzDataProtectionRecoveryPoint
cmdlet.$recoveryPointsCrr = Get-AzDataProtectionRecoveryPoint -BackupInstanceName $instance.Name -ResourceGroupName $resourceGroupName -ResourceGroupName $resourceGroupName e -SubscriptionId $subscriptionId -UseSecondaryRegion
Prepare the restore request.
To restore the database, follow one of the following methods:
Restore as database
Follow these steps:
Create the Azure Resource Manager ID for the new PostgreSQL database. You need to create this with the target PostgreSQL server to which permissions are assigned. Additionally, create the required PostgreSQL database name.
For example, you can name a PostgreSQL database as
emprestored21
under a target PostgreSQL servertargetossserver
in a resource grouptargetrg
with a different subscription.$targetResourceId = "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx/resourceGroups/targetrg/providers/providers/Microsoft.DBforPostgreSQL/servers/targetossserver/databases/emprestored21"
Use the
Intialize-AzDataProtectionRestoreRequest
cmdlet to prepare the restore request with relevant details.$OssRestoreReq = Initialize-AzDataProtectionRestoreRequest -DatasourceType AzureDatabaseForPostgreSQL -SourceDataStore VaultStore -RestoreLocation $vault.ReplicatedRegion[0] -RestoreType AlternateLocation -RecoveryPoint $recoveryPointsCrr[0].Property.RecoveryPointId -TargetResourceId $targetResourceId -SecretStoreURI $secretURI -SecretStoreType AzureKeyVault
Restore as files
Follow these steps:
Fetch the Uniform Resource Identifier (URI) of the container, in the storage account to which permissions are assigned.
For example, a container named
testcontainerrestore
under a storage accounttestossstorageaccount
with a different subscription.$contURI = https://testossstorageaccount.blob.core.windows.net/testcontainerrestore
Use the
Intialize-AzDataProtectionRestoreRequest
cmdlet to prepare the restore request with relevant details.$OssRestoreReq = Initialize-AzDataProtectionRestoreRequest -DatasourceType AzureDatabaseForPostgreSQL -SourceDataStore VaultStore -RestoreLocation $vault.ReplicatedRegion[0] -RestoreType RestoreAsFiles -RecoveryPoint $recoveryPointsCrr[0].Property.RecoveryPointId -TargetContainerURI $targetContainerURI -FileNamePrefix $fileNamePrefix
Validate the PostgreSQL database restore configuration
To validate the probabilities of success for the restore operation, run the following cmdlet:
$validate = Test-AzDataProtectionBackupInstanceRestore -ResourceGroupName $ResourceGroupName -Name $instance[0].Name -VaultName $VaultName -RestoreRequest $OssRestoreReq -SubscriptionId $SubscriptionId -RestoreToSecondaryRegion #-Debug
Trigger the restore operation
To trigger the restore operation, run the following cmdlet:
$restoreJob = Start-AzDataProtectionBackupInstanceRestore -BackupInstanceName $instance.Name -ResourceGroupName $ResourceGroupName -VaultName $vaultName -SubscriptionId $SubscriptionId -Parameter $OssRestoreReq -RestoreToSecondaryRegion # -Debug
Track the restore job
To monitor the restore job progress, choose one of the methods:
To get the complete list of Cross Region Restore jobs from the secondary region, run the following cmdlet:
$job = Get-AzDataProtectionJob -ResourceGroupName $resourceGroupName -SubscriptionId $subscriptionId -VaultName $vaultName -UseSecondaryRegion
To get a single job detail, run the following cmdlet:
$restoreJob = Start-AzDataProtectionBackupInstanceRestore -BackupInstanceName $instance.Name -ResourceGroupName $ResourceGroupName -VaultName $vaultName -SubscriptionId $SubscriptionId -Parameter $OssRestoreReq -RestoreToSecondaryRegion # -Debug
Next steps
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for