General Availability of Flexible Maintenance for Azure Database for MySQL - Flexible Server

  • Thread starter Thread starter Elendil
  • Start date Start date
E

Elendil

We're excited to announce that Flexible Maintenance for Azure Database for MySQL - Flexible Server is now Generally Available (GA)! This new feature enables greater control over the timing of the maintenance activities performed on database instances, so that customers can align maintenance schedules with their operational needs.



During public preview, we received extensive feedback that helped us to refine and enhance the feature for GA. We've incorporated several important updates to ensure a smoother and more flexible maintenance experience.



Key Features in GA​




Reschedule via Azure CLI​


With the GA release, users can now reschedule maintenance activities through the Azure CLI. This provides flexibility and automation for managing maintenance windows across multiple servers.



Expanded Reschedule Window​


The reschedule window has been extended to cover all available maintenance dates within the region, offering much more flexibility compared to the limited 14-day window from the public preview.



Demo: Batch Rescheduling Maintenance Using a Script​


One of the most powerful features introduced in the GA version is the ability to automate the rescheduling of maintenance activities for multiple servers across a subscription or within specific resource groups. Below is a script that can be used to batch reschedule maintenance for all servers in a subscription or resource group.





Code:
#!/bin/bash

# Function to display usage information
usage() {
    echo "Usage: $0 -s <subscription_id> [-g <resource_group>] -t <start_time> -m <maintenance_name>"
    echo "  -s: Subscription ID (required)"
    echo "  -g: Resource group name (optional, if not specified all resource groups will be iterated)"
    echo "  -t: Maintenance start time in 'YYYY-MM-DDTHH:MM:SSZ' format (required)"
    echo "  -m: Maintenance name (required)"
    exit 1
}

# Parse command-line arguments
while getopts "s:g:t:m:" opt; do
    case $opt in
        s) SUBSCRIPTION_ID="$OPTARG" ;;
        g) RESOURCE_GROUP="$OPTARG" ;;
        t) START_TIME="$OPTARG" ;;
        m) MAINTENANCE_NAME="$OPTARG" ;;
        *) usage ;;
    esac
done

# Ensure required parameters are provided
if [ -z "$SUBSCRIPTION_ID" ] || [ -z "$START_TIME" ] || [ -z "$MAINTENANCE_NAME" ]; then
    echo "Error: Subscription ID, maintenance start time, and maintenance name are required"
    usage
fi

# Set the Azure CLI subscription
az account set --subscription $SUBSCRIPTION_ID

# If no resource group is specified, retrieve all resource groups
if [ -z "$RESOURCE_GROUP" ]; then
    resource_groups=$(az group list --query "[].name" -o tsv)
else
    resource_groups=$RESOURCE_GROUP
fi

# Iterate through each resource group
for rg in $resource_groups; do
    echo "Checking resource group: $rg"

    # List all MySQL Flexible Servers in the current resource group
    mysql_servers=$(az mysql flexible-server list --resource-group $rg --query "[].name" -o tsv)
    
    if [ -n "$mysql_servers" ]; then
        for server in $mysql_servers; do
            echo "Attempting to reschedule maintenance for MySQL Flexible Server '$server' in resource group '$rg'."
            
            # Construct the CLI command
            command="az mysql flexible-server maintenance reschedule --resource-group $rg --server-name $server --maintenance-name $MAINTENANCE_NAME --start-time $START_TIME"
            
            # Print the command that will be executed
            echo "Running command: $command"
            
            # Execute the command and handle errors
            if eval $command; then
                echo "Successfully rescheduled maintenance for server '$server'."
            else
                echo "Failed to reschedule maintenance for server '$server'." >&2
            fi
        done
    else
        echo "No MySQL Flexible Servers found in resource group '$rg'."
    fi

    echo "---------------------------------------"
done





How to use the script​




Save the script

Copy the above script and save it to a file with a .sh extension, for example, reschedule_maintenance.sh.



Make the script executable

After you save the script, you need to make it executable by running the following command:



chmod +x reschedule_maintenance.sh



Run the script

After making the script executable, you can run it by passing the required parameters:





./reschedule_maintenance.sh -s <subscription_id> -g <resource_group> -t "2024-09-21T09:00:00Z" -m <maintenance_name>





This command contains the following parameters:



-s: Your Azure subscription ID.

-g: The resource group name (optional). If not provided, the script will iterate through all resource groups.

-t: The maintenance start time in the format YYYY-MM-DDTHH:MM:SSZ.

-m: The maintenance name (tracking ID) obtained from the portal, CLI, or maintenance notification email.



Notes on the -m parameter​


The -m parameter refers to the maintenance Tracking ID, which identifies the specific maintenance operation. You can retrieve this tracking ID in the following ways:

  • From the maintenance notification email sent by Azure.
  • By checking the Azure portal under the maintenance blade for your server.
  • By using the Azure CLI command to list the maintenance details for your server

For the same maintenance cycle in a region, the tracking ID will be the same for all servers. Therefore, if you have multiple servers in the same region, you can use the same -m value for all of them.



View maintenance status via CLI​


In addition to rescheduling, you can also use the CLI to batch view the maintenance status of all servers in a resource group. This allows you to check all maintenance schedules without navigating through the portal manually.



For more details on how to check maintenance status and automate maintenance tasks, see the article az mysql flexible-server maintenance.



Conclusion​


With the GA release of Flexible Maintenance, users now have the power to fully control when maintenance is performed on their Azure Database for MySQL Flexible Servers. The addition of Azure CLI integration for rescheduling and features like expanded reschedule windows makes managing maintenance simpler and more effective.



We encourage you to try out this new feature and leverage automation tools like the provided script to streamline your maintenance processes. For more detailed information, see the article Scheduled maintenance - Azure Database for MySQL - Flexible Server.



If you have any queries or suggestions, please let us know by leaving a comment below or by contacting directly us at AskAzureDBforMySQL@service.microsoft.com.

Continue reading...
 
Back
Top