简体   繁体   中英

Build a similar VM from an existing VM in Azure

I am new to Azure. I have this existing VM. It was built by my colleague and I think he built it through the Marketplace with the Azure portal.

Now I want to build a new one with the same settings (that have the same performance spec) such as the VM sku, OS disk, and data disk. I don't want to keep any existing data. It will be built in a different RG with a different VNet and su.net. What is the best way to do it?

I tried to "export template" on the current VM but I think the JSON file just specifies the existing disks and NIC to use, instead of creating new ones. Here is what it looks like

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "virtualMachines_myCurrentVM_name": {
        "defaultValue": "myCurrentVM",
        "type": "String"
    },
    "disks_myCurrentVM_OsDisk_1_xxxxxx_externalid": {
        "defaultValue": "/subscriptions/12345678-abcd-abcd-abcd-12345678/resourceGroups/nmtprdarmrgp001/providers/Microsoft.Compute/disks/myCurrentVM_OsDisk_1_xxxxxx",
        "type": "String"
    },
    "disks_myCurrentVM_DataDisk_0_externalid": {
        "defaultValue": "/subscriptions/12345678-abcd-abcd-abcd-12345678/resourceGroups/nmtprdarmrgp001/providers/Microsoft.Compute/disks/myCurrentVM_DataDisk_0",
        "type": "String"
    },
    "networkInterfaces_myCurrentVM290_externalid": {
        "defaultValue": "/subscriptions/12345678-abcd-abcd-abcd-12345678/resourceGroups/nmtprdarmrgp001/providers/Microsoft.Network/networkInterfaces/myCurrentVM290",
        "type": "String"
    }
},
"variables": {},
"resources": [
    {
        "type": "Microsoft.Compute/virtualMachines",
        "apiVersion": "2021-11-01",
        "name": "[parameters('virtualMachines_myCurrentVM_name')]",
        "location": "westus2",
        "tags": {
            "a": "1",
            "b": "2"
        },
        "plan": {
            "name": "f5-bigiq-virtual-edition-byol",
            "product": "f5-big-iq",
            "publisher": "f5-networks"
        },
        "properties": {
            "hardwareProfile": {
                "vmSize": "Standard_D4_v3"
            },
            "storageProfile": {
                "imageReference": {
                    "publisher": "f5-networks",
                    "offer": "f5-big-iq",
                    "sku": "f5-bigiq-virtual-edition-byol",
                    "version": "latest"
                },
                "osDisk": {
                    "osType": "Linux",
                    "name": "[concat(parameters('virtualMachines_myCurrentVM_name'), '_OsDisk_1_xxxxxx')]",
                    "createOption": "FromImage",
                    "caching": "ReadWrite",
                    "managedDisk": {
                        "storageAccountType": "StandardSSD_LRS",
                        "id": "[parameters('disks_myCurrentVM_OsDisk_1_xxxxxx_externalid')]"
                    },
                    "deleteOption": "Detach",
                    "diskSizeGB": 120
                },
                "dataDisks": [
                    {
                        "lun": 0,
                        "name": "[concat(parameters('virtualMachines_myCurrentVM_name'), '_DataDisk_0')]",
                        "createOption": "Attach",
                        "caching": "ReadOnly",
                        "writeAcceleratorEnabled": false,
                        "managedDisk": {
                            "storageAccountType": "StandardSSD_LRS",
                            "id": "[parameters('disks_myCurrentVM_DataDisk_0_externalid')]"
                        },
                        "deleteOption": "Detach",
                        "diskSizeGB": 128,
                        "toBeDetached": false
                    }
                ]
            },
            "osProfile": {
                "computerName": "[parameters('virtualMachines_myCurrentVM_name')]",
                "adminUsername": "azureuser",
                "linuxConfiguration": {
                    "disablePasswordAuthentication": true,
                    "ssh": {
                        "publicKeys": [
                            {
                                "path": "/home/azureuser/.ssh/authorized_keys",
                                "keyData": "ssh-rsa <some key here>"
                            }
                        ]
                    },
                    "provisionVMAgent": true,
                    "patchSettings": {
                        "patchMode": "ImageDefault",
                        "assessmentMode": "ImageDefault"
                    }
                },
                "secrets": [],
                "allowExtensionOperations": true,
                "requireGuestProvisionSignal": true
            },
            "networkProfile": {
                "networkInterfaces": [
                    {
                        "id": "[parameters('networkInterfaces_myCurrentVM290_externalid')]"
                    }
                ]
            },
            "diagnosticsProfile": {
                "bootDiagnostics": {
                    "enabled": true
                }
            }
        }
    }
]

}

Is it the best way to edit and modify the JSON file, or there is another way to do this? Thanks!

Thank you Matan Shabtay . Posting your suggestion as answer to help other community members.

From deployment Section (of the resource group where the VM is currently residing) you would get deployment history. Use that templet to replicate your your VM.

  1. Select the resource group you want to examine. 在此处输入图像描述

  2. Select the link under Deployments . 在此处输入图像描述

  3. Select one of the deployments from the deployment history. 在此处输入图像描述

  4. You can use the view templet option在此处输入图像描述

Reference: https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/deployment-history?tabs=azure-portal

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM