使用 Azure CLI 处理计划内维护通知Handling planned maintenance notifications using the Azure CLI

本文适用于同时运行 Linux 和 Windows 的虚拟机。This article applies to virtual machines running both Linux and Windows.

可以使用 CLI 查看何时安排 VM 进行维护You can use the CLI to see when VMs are scheduled for maintenance. 可通过 az vm get-instance-view 获得计划内维护信息。Planned maintenance information is available from az vm get-instance-view.

仅当有计划内维护时,才会返回维护信息。Maintenance information is returned only if there is maintenance planned.

az vm get-instance-view -n myVM -g myResourceGroup --query instanceView.maintenanceRedeployStatus

启动维护Start maintenance

如果 IsCustomerInitiatedMaintenanceAllowed 设置为 true,以下调用会在 VM 上启动维护。The following call will start maintenance on a VM if IsCustomerInitiatedMaintenanceAllowed is set to true.

az vm perform-maintenance -g myResourceGroup -n myVM 

经典部署Classic deployments

重要

经典 VM 将于 2023 年 3 月 1 日停用。Classic VMs will be retired on March 1, 2023.

如果从 ASM 使用 IaaS 资源,请在 2023 年 3 月 1 日之前完成迁移。If you use IaaS resources from ASM, please complete your migration by March 1, 2023. 我们建议你尽快进行切换,以利用 Azure 资源管理器中的许多增强功能。We encourage you to make the switch sooner to take advantage of the many feature enhancements in Azure Resource Manager.

有关详细信息,请参阅在 2023 年 3 月 1 日之前将 IaaS 资源迁移到 Azure 资源管理器For more information, see Migrate your IaaS resources to Azure Resource Manager by March 1, 2023.

如果你仍有通过使用经典部署模型部署的旧 VM,则可以使用 Azure 经典 CLI 查询 VM,并启动维护。If you still have legacy VMs that were deployed using the classic deployment model, you can use the Azure classic CLI to query for VMs and initiate maintenance.

通过键入以下内容确保在正确模式下使用经典 VM:Make sure you are in the correct mode to work with classic VM by typing:

azure config mode asm

若要获取名为 myVM 的 VM 维护状态,请键入:To get the maintenance status of a VM named myVM, type:

azure vm show myVM 

若要在名为 myVM 的经典 VM 的 myService 服务和 myDeployment 部署中启动维护,请键入:To start maintenance on your classic VM named myVM in the myService service and myDeployment deployment, type:

azure compute virtual-machine initiate-maintenance --service-name myService --name myDeployment --virtual-machine-name myVM

后续步骤Next steps

还可以使用 Azure PowerShell门户处理计划内维护。You can also handle planned maintenance using the Azure PowerShell or portal.