Azure Python SDK从恢复服务(备份)检索备份项目

发布于 2025-01-22 18:06:16 字数 1160 浏览 3 评论 0 原文

有人告诉我将我的BASH脚本报告有关VM备份状态的报告,还报告了未备份到Azure Automation帐户的VM。我选择了Python,因为自动化帐户没有bash,并且我以前曾在系统管理目的中完成Python脚本。我不是Python开发人员,我需要帮助导航Azure Python SDK类。

我需要在Python SDK模块之一中在门户网站中找到“备份项目”,以从备份库中检索VM信息。我已经尝试了azure.mgmt.recoveryServices和azure.mgmt.recoveryservicesbackup。我可以从azure.mgmt.recoveryservices获取保险库信息,我可以用来查询有关VAULT的更多信息,希望能VM信息。我的猜测是azure.mgmt.recoveryservicesbackup。但是我迷失在azure.mgmt.recoveryservicesbackup.jobs.models中。我不能在数百个课程中分辨,哪个会提供这些信息。

我想将Vault备份的输出与VM列表相对,以找出哪些没有备份。

我已经看过:

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:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

默嘫て 2025-01-29 18:06:17

使用Python获取VM的备份,

您可以使用以下代码片段获取VM备份详细信息。

from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.compute import ComputeManagementClient
from azure.mgmt.network import NetworkManagementClient
import requests

SUBSCRIPTION_ID = '<Your Subscription ID>'
VM_NAME = '<VM Name>'

credentials = ServicePrincipalCredentials(
    client_id='<Client id>',
    secret='<Client Secret>',
    tenant='<Your Tenent Id>'
)

# Creating base URL 
BASE_API_URL = "https://management.azure.com/Subscriptions/<Subscription>/resourceGroups/<Resourece group name>/providers/Microsoft.RecoveryServices/vaults/your_vault_name/backupProtectedItems?api-version=2019-05-13&"

# Add the required filter to fetch the Exact details
customFilter="$filter=backupManagementType eq 'AzureIaasVM' and itemType eq 'VM' and policyName eq 'DailyPolicy'"

#Adding the Base API url with custom filter
BASE_URL = BASE_API_URL + customFilter

header = {
    "Authorization": 'Bearer '+ credentials.token["access_token"]
}

response = requests.get(BASE_URL, headers=header)

# here you can handle the response to know the details of backup
print(response.content)
...

请参阅在这里a>使用Azure CLI实现。

Using python to get the backup of VM

You can use the below code snippet to get VM Backup details.

from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.compute import ComputeManagementClient
from azure.mgmt.network import NetworkManagementClient
import requests

SUBSCRIPTION_ID = '<Your Subscription ID>'
VM_NAME = '<VM Name>'

credentials = ServicePrincipalCredentials(
    client_id='<Client id>',
    secret='<Client Secret>',
    tenant='<Your Tenent Id>'
)

# Creating base URL 
BASE_API_URL = "https://management.azure.com/Subscriptions/<Subscription>/resourceGroups/<Resourece group name>/providers/Microsoft.RecoveryServices/vaults/your_vault_name/backupProtectedItems?api-version=2019-05-13&"

# Add the required filter to fetch the Exact details
customFilter="$filter=backupManagementType eq 'AzureIaasVM' and itemType eq 'VM' and policyName eq 'DailyPolicy'"

#Adding the Base API url with custom filter
BASE_URL = BASE_API_URL + customFilter

header = {
    "Authorization": 'Bearer '+ credentials.token["access_token"]
}

response = requests.get(BASE_URL, headers=header)

# here you can handle the response to know the details of backup
print(response.content)
...

Refer here to achieve using Azure cli.

治碍 2025-01-29 18:06:17

我正在寻找的是“ backup_protected_item”,在recoveryServicesBackupclient构造器中,这是示例代码。

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)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文