我需要查询哪些属性来启用zure VM的备份策略或不使用Python Azure SDk。任何参考和示例均会受到赞赏
我在下面提到了azure文档,但我在这里找不到备份部分。
def get_vm(compute_client):
vm = compute_client.virtual_machines.get(GROUP_NAME, VM_NAME, expand='instanceView')
print("hardwareProfile")
print(" vmSize: ", vm.hardware_profile.vm_size)
print("\nstorageProfile")
print(" imageReference")
print(" publisher: ", vm.storage_profile.image_reference.publisher)
print(" offer: ", vm.storage_profile.image_reference.offer)
print(" sku: ", vm.storage_profile.image_reference.sku)
print(" version: ", vm.storage_profile.image_reference.version)
print(" osDisk")
print(" osType: ", vm.storage_profile.os_disk.os_type.value)
print(" name: ", vm.storage_profile.os_disk.name)
print(" createOption: ", vm.storage_profile.os_disk.create_option.value)
print(" caching: ", vm.storage_profile.os_disk.caching.value)
print("\nosProfile")
print(" computerName: ", vm.os_profile.computer_name)
print(" adminUsername: ", vm.os_profile.admin_username)
print(" provisionVMAgent: {0}".format(vm.os_profile.windows_configuration.provision_vm_agent))
print(" enableAutomaticUpdates: {0}".format(vm.os_profile.windows_configuration.enable_automatic_updates))
print("\nnetworkProfile")
for nic in vm.network_profile.network_interfaces:
print(" networkInterface id: ", nic.id)
print("\nvmAgent")
print(" vmAgentVersion", vm.instance_view.vm_agent.vm_agent_version)
print(" statuses")
for stat in vm_result.instance_view.vm_agent.statuses:
print(" code: ", stat.code)
print(" displayStatus: ", stat.display_status)
print(" message: ", stat.message)
print(" time: ", stat.time)
print("\ndisks");
for disk in vm.instance_view.disks:
print(" name: ", disk.name)
print(" statuses")
for stat in disk.statuses:
print(" code: ", stat.code)
print(" displayStatus: ", stat.display_status)
print(" time: ", stat.time)
print("\nVM general status")
print(" provisioningStatus: ", vm.provisioning_state)
print(" id: ", vm.id)
print(" name: ", vm.name)
print(" type: ", vm.type)
print(" location: ", vm.location)
print("\nVM instance status")
for stat in vm.instance_view.statuses:
print(" code: ", stat.code)
print(" displayStatus: ", stat.display_status)
答案 0 :(得分:1)
我正在使用Backup Protected Items - List api来做。
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 = 'xxx'
VM_NAME = 'xxx'
credentials = ServicePrincipalCredentials(
client_id='xxx',
secret='xxx',
tenant='xxx'
)
BASE_URL = "https://management.azure.com/Subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.RecoveryServices/vaults/your_vault_name/backupProtectedItems?api-version=2019-05-13&"
myfilter="$filter=backupManagementType eq 'AzureIaasVM' and itemType eq 'VM' and policyName eq 'DailyPolicy'"
BASE_URL = BASE_URL + myfilter
headers = {
"Authorization": 'Bearer '+ credentials.token["access_token"]
}
response = requests.get(BASE_URL, headers=headers)
print(response.content)
请注意,您应该注意response.content
,编写代码将其转换为真实的json格式。然后从json获取相关值。
答案 1 :(得分:1)
备份是Azure中的另一项服务。这不是Azure VM中的设置。
您可以按照快速入门 Back up a virtual machine in Azure with the CLI 进行操作。
它将向您展示如何通过CLI或Protal备份虚拟机:)