DR environment for Azure Api Management | backup and restore

2016, Oct 25    

Azure API Management allows the entire service configuration to be backed up to a storage account.
Either on an ad-hoc basis or on a predefined schedule using Azure Automation, you can back up and restore the configuration to another API Management instance (in another region for DR).

I’ve found that it takes about 15 minutes to restore the configuration, during which you cannot make any other changes to the APIM service, or use the Publisher/Developer portal. This includes any changes that you try to apply using Powershell/Xplat-cli/API, you will receive an error that you cannot make changes whilst the configuration is being applied.

It should be noted that after restoration, the usage statistics are not carried across, the APIM instances usage statistics will remain. The backup/restore is really intended for syncing Production with other non Production environments (DR, Pre-prod, etc). Not to be used to apply release changes to your production environment.

Official MSDN Docs;
Backup-AzureRmApiManagement : https://msdn.microsoft.com/en-us/library/mt619281.aspx
Restore-AzureRmApiManagement : https://msdn.microsoft.com/en-us/library/mt619278.aspx

Powershell script


#Select the APIM instance to 
$sourceApim = Get-AzureRmApiManagement | Where-Object {$_.Name -eq "mymainapiminstance"}
$destinationApim = Get-AzureRmApiManagement | Where-Object {$_.Name -eq "myDRapiminstance"}

#Select the storage account to hold the backup
$storagecontext = New-AzureStorageContext -StorageAccountKey mystorageacountprimarykey -StorageAccountName mystorageaccountname

#Get todays date as a string for the backup filename
$todaysdate = get-date -Format "yyyyMMdd-HHmm"

#Perform APIM config backup
Backup-AzureRmApiManagement -ResourceGroupName $sourceApim.ResourceGroupName -Name $sourceApim.Name -StorageContext $StorageContext -TargetContainerName $containername -TargetBlobName $blobname

#Restore APIM
Restore-AzureRmApiManagement -ResourceGroupName $destinationApim.ResourceGroupName -Name $destinationApim.Name -StorageContext $StorageContext -SourceContainerName $containername -SourceBlobName $blobname