Azure Recovery Services Backup Management

10.0.0 · active · verified Thu Apr 09

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

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate the `RecoveryServicesBackupClient` using `DefaultAzureCredential` for authentication and then lists existing backup policies within a specified Recovery Services Vault. Ensure you have Azure credentials configured (e.g., via `az login` or environment variables).

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.")

view raw JSON →