需要 Python 进程将 AZURE BackupPolicy 分配给文件共享

问题描述 投票:0回答:1

在 Python 程序中,我根据某些参数创建存储帐户和文件共享,并且需要将现有备份策略分配给这个新文件共享。

我已经在 Powershell 中找到了执行此操作的方法(我认为:如下,来自 AZURE 站点。

$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

但是还没有找到Python 的等价物。我怀疑它挂在某处

RecoveryServicesBackupClient
但还没有成功。

python azure backup azure-file-share
1个回答
0
投票

需要 Python 进程将 AZURE BackupPolicy 分配给文件共享

您可以使用以下 Python 代码将

Azure BackupPolicy
分配给文件共享。

代码:

from azure.identity import DefaultAzureCredential
from azure.mgmt.recoveryservicesbackup import RecoveryServicesBackupClient

def main():
    client = RecoveryServicesBackupClient(
        credential=DefaultAzureCredential(),
        subscription_id="xxxxx",
    )
    response = client.protected_items.create_or_update(
        vault_name="azurefilesvault",
        resource_group_name="xxxxx",
        fabric_name="Azure",
        container_name="StorageContainer;storage;xxxxxx;venkat789",
        protected_item_name="AzureFileShare;xxxxxx",
        parameters={
            "properties": {
                "policyId": "/subscriptions/xxxx/resourceGroups/xxxx/providers/Microsoft.RecoveryServices/vaults/azurefilesvault/backupPolicies/policy2",
                "protectedItemType": "AzureFileShareProtectedItem",
                "sourceResourceId": "/subscriptions/xxxxf/resourceGroups/xxx/providers/Microsoft.Storage/storageAccounts/venkat789/fileServices/default/shares/share1",
            }
        },
    )
    print(response)

if __name__ == "__main__":
    main()

上述代码使用 Azure SDK for PythonAzure 恢复服务保管库中创建或更新受保护项目。它使用

RecoveryServicesBackupClient
类和
create_or_update()
方法,传入必要的参数,包括保管库名称、资源组名称、结构名称、容器名称、受保护项目名称以及受保护的参数字典物品。 create_or_update() 方法的响应将打印到控制台。

输出:

enter image description here

参考: 受保护的项目 - 创建或更新 - REST API(Azure 恢复服务 - 备份)|微软学习

© www.soinside.com 2019 - 2024. All rights reserved.