Azure Recovery Services Backup Management
The Azure Recoveryservicesbackup Management Client Library for Python allows developers to programmatically manage Azure Recovery Services Backup resources, including vaults, backup policies, protected items, and jobs. Version 10.0.0 aligns with the Azure SDK Track 2 guidelines. Azure SDKs typically have a frequent release cadence, often with minor updates and major releases tied to API version changes.
Warnings
- breaking Version 10.0.0 marks a significant transition to Azure SDK Track 2 guidelines. This involves changes to client constructors, authentication mechanisms (requiring `azure-identity`), method signatures, and return types. Code written for older Track 1 versions (e.g., `< 10.0.0`) will not work without modification.
- gotcha Authentication is a common point of failure. `DefaultAzureCredential` requires proper environment configuration (e.g., `AZURE_TENANT_ID`, `AZURE_CLIENT_ID`, `AZURE_CLIENT_SECRET`) or an an active Azure CLI login (`az login`). Without valid credentials, client instantiation or subsequent API calls will fail with `CredentialUnavailableError` or similar.
- gotcha Many management operations require precise resource identifiers such as `subscription_id`, `resource_group_name`, `vault_name`, and nested resource names (e.g., `policy_name`). Incorrect or misspelled identifiers will lead to 'ResourceNotFound' errors or similar failures.
Install
-
pip install azure-mgmt-recoveryservicesbackup azure-identity
Imports
- RecoveryServicesBackupClient
from azure.mgmt.recoveryservicesbackup import RecoveryServicesBackupClient
Quickstart
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.recoveryservicesbackup import RecoveryServicesBackupClient
# Replace with your actual subscription ID and resource details
# It's recommended to set these as environment variables for production.
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "<your-subscription-id>")
resource_group_name = os.environ.get("AZURE_RESOURCE_GROUP_NAME", "<your-resource-group>")
vault_name = os.environ.get("AZURE_RECOVERY_SERVICES_VAULT_NAME", "<your-recovery-services-vault-name>")
# Authenticate using DefaultAzureCredential
# This tries several methods: environment variables, Azure CLI, Managed Identity, etc.
credential = DefaultAzureCredential()
# Create the Backup Management client
client = RecoveryServicesBackupClient(credential, subscription_id)
print(f"Listing backup policies in vault '{vault_name}' in resource group '{resource_group_name}'...")
try:
# Example: List backup policies within a specified vault
# Note: Ensure the credential has 'Reader' access or higher to the vault/resource group.
policies = client.backup_policies.list(resource_group_name, vault_name)
for policy in policies:
print(f" - Policy Name: {policy.name}, State: {policy.properties.backup_management_type}")
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure the vault, resource group, and subscription ID are correct and your credential has sufficient permissions.")