Automating Backup and Restore of Azure Maintenance Configurations

Introduction

While re-architecting one my customers Azure Arc for servers setup, including related components and services, I needed a way to manage Maintenance Configurations across environments. Manual reconfiguration seemed time-consuming and error-prone, so I developed a PowerShell script to automate the process.

The Challenge with Maintenance Configurations

It’s important to understand a key limitation: the Maintenance Configuration schema doesn’t include dynamic scoping data or direct assignments. These are separate objects in Azure that need to be handled independently. This separation can make comprehensive backups and restorations more complex than they initially appear.

				
					{
    "location": "westeurope",
    "tags": {},
    "properties": {
        "extensionProperties": {
            "InGuestPatchMode": "User"
        },
        "maintenanceScope": "InGuestPatch",
        "maintenanceWindow": {
            "startDateTime": "2024-08-28 00:00",
            "duration": "03:55",
            "timeZone": "FLE Standard Time",
            "recurEvery": "1Day"
        },
        "visibility": "Custom",
        "installPatches": {
            "rebootSetting": "IfRequired",
            "windowsParameters": {
                "classificationsToInclude": [
                    "Critical",
                    "Security"
                ]
            },
            "linuxParameters": {
                "classificationsToInclude": [
                    "Critical",
                    "Security"
                ]
            }
        },
        "configurationType": "Regular"
    },
    "id": "/subscriptions/XXXXX/resourcegroups/XXX/providers/microsoft.maintenance/maintenanceconfigurations/XXX,
    "name": "XXX",
    "type": "Microsoft.Maintenance/maintenanceConfigurations"
}
				
			

The PowerShell Script Solution

To address this challenge, I created a script that automates the backup and restore process for the core Maintenance Configuration settings. Here’s an overview of the script:

This section is reserved for our Premium Members only. Upgrade your membership to access this solution and unlock more benefits.

How It Works

  1. The script retrieves all Maintenance Configurations from the specified source subscription and resource group.
  2. It saves each configuration as a JSON file in a local directory.
  3. The script then restores these configurations to the specified destination subscription and resource group.

Listing Configuration Assignments with Azure Resource Graph Explorer

While our PowerShell script handles the core Maintenance Configuration settings, it doesn’t cover the configuration assignments, which include both dynamic scopes and direct assignments. To list these, we can use Azure Resource Graph Explorer. Here’s how:

  1. Navigate to the Azure portal and search for “Resource Graph Explorer“.
  2. In the query window, you can use the following KQL (Kusto Query Language) query to list all assignments for a specific Maintenance Configuration:

This section is reserved for our Premium Members only. Upgrade your membership to access this solution and unlock more benefits.

Replace {subscriptionId}, {resourceGroupName}, and {configurationName} with your specific values.

Limitations and Considerations

While this script simplifies the process of backing up and restoring Maintenance Configurations, it’s important to note its limitations:

  1. It only handles the core Maintenance Configuration settings.
  2. Dynamic scoping data and direct assignments are not included in this backup and restore process.
  3. Always test the script in a non-production environment before using it in your production setup.

Conclusion

This PowerShell script provides a starting point for automating the backup and restore process of Maintenance Configurations in Azure. While it doesn’t cover every aspect of your maintenance setup, it can reduce the time and potential for errors in managing these configurations across different environments.

By sharing this script, I hope to help other Azure administrators who might face similar challenges in managing their environments. Feel free to adapt and improve upon this script to better suit your specific needs.

Remember, automation can help in managing complex Azure environments. This script is one step towards making our Azure management tasks more manageable and less prone to human error. For more advanced Azure management techniques and personalized guidance, consider joining our exclusive membership program.

Leave a Comment

Contact me

If you’re interested in learning about Automating Backup and Restore of Azure Maintenance Configurations. I can help you understand how this solution can benefit your organization and provide a customized solution tailored to your specific needs.

Table of Contents