Within a Python program, I'm creating storage accounts and fileshares based on some parameters, and need to assign an existing backup policy to this new fileshare.
I've found the method to do this in Powershell (I think: below, from the AZURE site.
$monthlyafsPol = Get-AzRecoveryServicesBackupProtectionPolicy -Name "monthlyafs"
$afsContainer = Get-AzRecoveryServicesBackupContainer -FriendlyName "testStorageAcct" -ContainerType AzureStorage
$afsBkpItem = Get-AzRecoveryServicesBackupItem -Container $afsContainer -WorkloadType AzureFiles -Name "testAzureFS"
Enable-AzRecoveryServicesBackupProtection -Item $afsBkpItem -Policy $monthlyafsPol
But haven't found the Python equivalent yet. I suspect it's hanging off RecoveryServicesBackupClient somewhere but no success yet.
You can use the below Python code for assigning an
Azure BackupPolicyto a file share.Code:
The above code creates or updates a protected item in an Azure Recovery Services vault using the Azure SDK for Python. It uses the
RecoveryServicesBackupClientclass and thecreate_or_update()method, passing in the necessary parameters including the vault name, resource group name, fabric name, container name, protected item name, and a dictionary of parameters for the protected item. The response from the create_or_update() method is printed to the console.Output:
Reference: Protected Items - Create Or Update - REST API (Azure Recovery Services - Backup) | Microsoft Learn