Azure APIM Backup HowTo
Why Backup Azure API Management
As I mentioned in my previous post showing you a script that you can use to backup APIM’s internal configuration data such as your user/subscriber data. Backing up API management via the resource manager API will also provide you a quicker, fuller restore in the event your APIM instances suffers a catastrophic issue. There may have been some errant commits that take it down or some other configuration reasons that your APIM doesn’t work any more. A quick call to the restore API, either via PowerShell or other SDK, can get your Azure API Management back up and running a few minutes while you track down what went wrong with your deployment.
I’ll show you how to set up the automated backup side of things, utilizing Azure Automation, but for information how to restore your APIM, check out the Microsoft documentation for the
Restore-AzApiManagement cmdlet located at this page. This is the cmdlet you’ll want to run to get your APIM back from the dead in the event of a disaster. Let’s get into how to set this up. We’ll cover creating/configuring the Automation Account, adding the back APIM script, and then, finally, scheduling it to run.
One thing to mention before we start is that no matter what we set the retention to later on, backups are good for a maximum of 30 days.
Setting Up Azure Automation
First thing is to set up an Azure Automation account to run the APIM backup script. We will need to the following items:
- Create the account
- Update the Modules
- Import the AzureRM.APIManagement Module
Create the Account
On the Automation blade, click Add. Fill out the form related to your information and you should be good to go.
Your Automation Account should be ready to go after a couple minutes.
Once the account is create, head into the account, click on the Modules section and then Update Azure Modules.
Next you’ll want to head over to the Modules Gallery to find and import the AzureRM.APIManagement module.
Setting up the Runbook
Click Create Runbook to get the runbook going. It needs to be of type PowerShell and not a workflow type. After you name it and select the type, click create.
On the next screen you can paste in the code for the APIM backup script referenced here and click Publish. From here we can go on the last step which is scheduling.
On the schedules tab click Add a Schedule. From there you will select the create a schedule. Most often, users would want a daily backup some time when there are no active changes to the configuration going on. Such changes will fail though your APIs will still function.
The final step is to input the parameters you’ll need to have this run successfully. Here is the list of parameters you’ll need:
- APIM Resource Group Name
- APIM Instance Name
- Storage Account Name
- Storage Account Key
- Blob Container Name (Where we’ll write the APIM Backup)
- Backup File Prefix
- Retention Days (to clean up files - backups are good for 30 days max)
- Subscription Name
I hope that you enjoyed this post and were able to follow along. If you enjoyed that, please consider heading over to the SysOptics Facebook group and letting us know that you were able to get this going. We always love to hear from IT pros out there getting it done and getting it done with cloud.