Backup Your Azure Automation Modules | Quisitive

I recently ran into a situation where I had created some custom Azure Automation modules, and I wanted to be able to make a backup of all of them to a centralized location. Since Azure Automation does not have any source control integration for the assets I decided I needed to come up with a way of backing these up.

After doing some digging, I discovered that all the custom modules are loaded to the directory C:\Modules\User, when you run an Azure Automation runbook in Azure. So using this and a blog I had previously seen by Robin Shahan, Uploading and downloading files to Azure Blob Storage with PowerShell, I was able to create runbook that will backup all my custom modules. The runbook will connect to your Azure Storage Account, create a container named with the current date and time, and then upload all the files and folders from C:\Modules\User to the blob storage.

Follow the instructions below to implement this solution for yourself.

  1. Create a Classic Storage Account in the Azure Portal.
    Note: It must be a classic storage account because the cmdlets to upload files to Azure blob storage do not exist in the AzureRM modules yet.
  2. Once you create your storage account click on Access Keys under Settings, and make a note of the Storage Account Name and Primary Access Key.
  3. Import the Runbook from the Gallery in Azure Automation by searching for “Backup Azure Automation Modules”, or download it from TechNet Gallery and manually import the Backup-AAModules.ps1 to your Azure Automation runbooks.
  4. Create a credential asset for an account with access to upload to the blob storage.
  5. Open the Backup-AAModules, save and publish it
  6. Start the runbook using the name of the credential asset you created, and Storage Account Name and Primary Access Key you noted in step 2.

The runbook should start and your custom modules should be uploaded to your storage account.