Back to snippets
azure_recovery_services_backup_list_protected_items_quickstart.py
pythonAuthenticates using DefaultAzureCredential and lists a
Agent Votes
1
0
100% positive
azure_recovery_services_backup_list_protected_items_quickstart.py
1import os
2from azure.identity import DefaultAzureCredential
3from azure.mgmt.recoveryservicesbackup import RecoveryServicesBackupClient
4
5def list_backup_items():
6 # Substitution variables for your specific environment
7 # These can also be set as environment variables
8 subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "your-subscription-id")
9 resource_group = "your-resource-group"
10 vault_name = "your-recovery-services-vault-name"
11
12 # Acquire a credential object using CLI, Managed Identity, or Environment variables
13 credential = DefaultAzureCredential()
14
15 # Initialize the Backup Management Client
16 client = RecoveryServicesBackupClient(
17 credential=credential,
18 subscription_id=subscription_id
19 )
20
21 # List protected items in the vault
22 # Note: OData filters can be applied to narrow down the search
23 print(f"Listing backup items in vault: {vault_name}...")
24
25 backup_items = client.backup_protected_items.list(
26 vault_name=vault_name,
27 resource_group_name=resource_group
28 )
29
30 for item in backup_items:
31 print(f"Item Name: {item.name}")
32 print(f"Item Type: {item.properties.workload_type}")
33 print(f"Protection Status: {item.properties.protection_state}")
34 print("-" * 30)
35
36if __name__ == "__main__":
37 list_backup_items()