当快照位于另一个资源组中时,从快照创建VM

发布于 2025-01-20 20:05:56 字数 463 浏览 3 评论 0原文

我使用Azure CLI命令从快照创建了VM 以下是从快照创建VM的脚本

az disk create -g $RD_OPTION_RESOURCEGROUP -n $RD_OPTION_DISKNAME --source $RD_OPTION_SNAPSHOTNAME
az vm create -g $RD_OPTION_RESOURCEGROUP -n $RD_OPTION_VMNAME --attach-os-disk $RD_OPTION_DISKNAME --os-type windows

此代码将创建Snapshot创建VM,其中快照位于一个资源组中,ABC表示ABC,那么新创建的VM也应该在同一资源组ABC中,

现在我需要像我这样找到的方式想要从快照和新创建的VM等快照创建VM,将在不同的资源组中……就像快照位于ABC资源组中,那么在另一个资源组中必须分配新创建的VM,请说XYZ,

请帮助我在此

I have created vm from snapshot using azure cli command
Below is the script for the creation of vm from snapshot

az disk create -g $RD_OPTION_RESOURCEGROUP -n $RD_OPTION_DISKNAME --source $RD_OPTION_SNAPSHOTNAME
az vm create -g $RD_OPTION_RESOURCEGROUP -n $RD_OPTION_VMNAME --attach-os-disk $RD_OPTION_DISKNAME --os-type windows

This code will create the vm from snapshot in which snapshot is in one resource group say abc then the newly creating vm should also in same resource group abc

now i need to find the way like i want to create a vm from snapshot like the snapshot and newly creating vm will be in different resource groups... like if snapshot is in abc resource group then the newly creating vm have to be allocated in the other resource group say xyz

Please help me out in this

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

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

发布评论

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

评论(1

半世晨晓 2025-01-27 20:05:56

要在不同资源组中创建一个从快照中创建VM,请使用以下CLI脚本复制快照:

  • 将变量定义为 sourcesubscriptionIdId 提供快照所在的订阅ID。
sourceSubscriptionId="<subscriptionId>"
  • 将变量定义为 sourcereSourceGroupName 在其中您必须在其中提供快照所在的资源组名称。
sourceResourceGroupName=yourSourceResourceGroupName
  • 定义一个变量,其中您必须提供 快照名称
snapshotName=mySnapshotName
  • 将上下文设置为 订阅ID 在其中存在快照。
az account set --subscription $sourceSubscriptionId
  • 使用以下CMDLET获取 快照ID
snapshotId=$(az snapshot show --name $snapshotName --resource-group $sourceResourceGroupName --query [id] -o tsv)
  • 定义变量 targetResourceGroupName 在其中快照将复制到:
targetResourceGroupName=mytargetResourceGroupName
  • 将快照 复制到其他资源组在CMDLET下方:
az snapshot create --resource-group $targetResourceGroupName --name $snapshotName --source $snapshotId --sku Standard_LRS

参考 azure-cli-samples/copy-snapshotsnapshot to-snapshot to-same-same-same-ordferty-subscription。 sh在主人·azure-samples/azure-cli-samples·github

To create a VM from Snapshot which is in different resource group, copy the snapshot using below CLI script:

  • Define a variable as sourceSubscriptionId where you have to provide the subscription ID in which your snapshot resides.
sourceSubscriptionId="<subscriptionId>"
  • Define a variable as sourceResourceGroupName where you have to provide the resource group name in which your snapshot resides.
sourceResourceGroupName=yourSourceResourceGroupName
  • Define a variable where you have to provide snapshot name.
snapshotName=mySnapshotName
  • Set the context to the subscription Id where snapshot exists.
az account set --subscription $sourceSubscriptionId
  • Use the below cmdlet to get the snapshot ID.
snapshotId=$(az snapshot show --name $snapshotName --resource-group $sourceResourceGroupName --query [id] -o tsv)
  • Define a variable targetResourceGroupName where snapshot will be copied to:
targetResourceGroupName=mytargetResourceGroupName
  • To copy the snapshot to different resource group try using the below cmdlet:
az snapshot create --resource-group $targetResourceGroupName --name $snapshotName --source $snapshotId --sku Standard_LRS

Reference : azure-cli-samples/copy-snapshot-to-same-or-different-subscription.sh at master · Azure-Samples/azure-cli-samples · GitHub.

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