Search code examples
pythonazuresdkbackupazure-keyvault

azure python SDK retrieve backup items from recoverservices(backup)


I was told to move my bash script that reports on VM backup status, also reports VMs that are not being backed up to Azure automation account. I picked python since Automation Account doesn't have bash and I have done python scripts before for system admin purposes. I am not a python developer, and I need help navigate Azure python SDK classes.

I need to find the "Backup Items" in portal from one of the python SDK modules, to retrieve the VM information from backup vault. I've tried azure.mgmt.recoveryservices and azure.mgmt.recoveryservicesbackup. I can get vault information from azure.mgmt.recoveryservices, which I can use to query more information about vault, hopefully the VM information. My guess is azure.mgmt.recoveryservicesbackup. But I am lost in azure.mgmt.recoveryservicesbackup.jobs.models. I can't tell among hundreds of classes, which one would give that information.

I'd like to use the output from vault backup to against the list of VMs, to find out which ones are not being backed up.

I've looked at:


Solution

  • what I was looking for is in "backup_protected_item", in RecoveryServicesBackupClient constructor, here is sample code.

    from  azure.mgmt.recoveryservicesbackup import RecoveryServicesBackupClient
    
    backup_items = backup_client.backup_protected_items.list(resource_group_name='rg_xxx', vault_name=var_vault)
    
    print(backup_items.properties)