{"id":195,"date":"2017-09-29T01:16:45","date_gmt":"2017-09-28T15:16:45","guid":{"rendered":"http:\/\/kswp01.azurewebsites.net\/?p=195"},"modified":"2019-11-13T16:57:36","modified_gmt":"2019-11-13T06:57:36","slug":"restoring-azure-vm","status":"publish","type":"post","link":"https:\/\/kswp01.azurewebsites.net\/?p=195","title":{"rendered":"Restore Azure VM"},"content":{"rendered":"<h3>Steps to restore AzureRM VM<\/h3>\n<p><!--more--><\/p>\n<p><span style=\"color: #ff0000;\">This information is outdated. Please refer to the links at the bottom of this page for the latest information.<\/span><\/p>\n<p>1. Restore the VM from &#8220;Backup Item&#8221; in the Vault and select Restore Type as &#8220;Restore disks&#8221;.<\/p>\n<p>2. Download the three .json files which have been created along with the VHD in the container of the storage account.<\/p>\n<p>3. Login to Azure via PowerShell<\/p>\n<pre>PS C:\\Windows\\system32&gt; Connect-AzAccount<\/pre>\n<p>4. Find the id of the availability set<\/p>\n<pre>PS C:\\Windows\\system32&gt; Get-AzAvailabilitySet -ResourceGroupName \"xxx\"<\/pre>\n<p>5. Find the following information below from the .json files which were downloaded in Step.2<\/p>\n<p>&#8211; VM-Size (e.g.\u00a0Standard_DS2_v2_Promo)<\/p>\n<p>&#8211; OS Disk URI (e.g. https:\/\/xxxxx\/xxxxx\/xxxx.vhd)<\/p>\n<p>&#8211; NIC ID (e.g\u00a0\/subscriptions\/xxx\/resourceGroups\/xxx\/providers\/Microsoft.Network\/networkInterfaces\/xxx)<\/p>\n<p>&#8211; Location (e.g.\u00a0australiasoutheast)<\/p>\n<p>6-1. Run the commands below if using unmanaged disk (Storage Account)<\/p>\n<pre>PS C:\\Windows\\system32&gt; <span class=\"hljs-variable\">$vm<\/span> = <span class=\"hljs-pscommand\">New-AzureRmVMConfig<\/span><span class=\"hljs-parameter\"> -VMName<\/span> &lt;<span class=\"hljs-pscommand\">VM-name<\/span>&gt;<span class=\"hljs-parameter\"> -VMSize<\/span> &lt;<span class=\"hljs-pscommand\">vm-size<\/span>&gt;<span class=\"hljs-parameter\"> -AvailabilitySetId<\/span> &lt;<span class=\"hljs-pscommand\">availability-set<\/span>-id&gt; \n\n<span class=\"hljs-pscommand\">PS C:\\Windows\\system32&gt; Set-AzureRmVMOSDisk<\/span><span class=\"hljs-parameter\"> -CreateOption<\/span> <span class=\"hljs-string\">\"Attach\"<\/span><span class=\"hljs-parameter\"> -VM<\/span> $vm<span class=\"hljs-parameter\"> -VhdUri<\/span> &lt;osDiskURI&gt;<span class=\"hljs-parameter\"> -Name<\/span> &lt;osDiskName&gt; [-Windows |<span class=\"hljs-parameter\"> -Linux<\/span>] \n\n----- If Data Disks available -----\n<span class=\"hljs-pscommand\">PS C:\\Windows\\system32&gt; Add-AzureRmVMDataDisk<\/span><span class=\"hljs-parameter\"> -VM<\/span> <span class=\"hljs-variable\">$vm<\/span><span class=\"hljs-parameter\"> -Name<\/span> &lt;DataDiskName&gt;<span class=\"hljs-parameter\"> -VhdUri<\/span> &lt;DataDiskURI&gt; <span class=\"hljs-parameter\">-Lun<\/span> &lt;LUN#&gt;<span class=\"hljs-parameter\"> -CreateOption<\/span> Attach \n-----------------------------------\n\nPS C:\\Windows\\system32&gt; <span class=\"hljs-pscommand\">Add-AzureRmVMNetworkInterface<\/span><span class=\"hljs-parameter\"> -VM<\/span> $vm<span class=\"hljs-parameter\"> -Id<\/span> &lt;nicId&gt; \n\nPS C:\\Windows\\system32&gt; <span class=\"hljs-pscommand\">New-AzureRmVM<\/span><span class=\"hljs-parameter\"> -ResourceGroupName<\/span> &lt;resourceGroupName&gt;<span class=\"hljs-parameter\"> -Location<\/span> &lt;location&gt;<span class=\"hljs-parameter\"> -VM<\/span> $vm<\/pre>\n<p>6-2. Run the command below if using managed disk<\/p>\n<pre>#Provide the name of your resource group \n$resourceGroupName ='xxx' \n\n#Provide the name of the snapshot that will be used to create OS disk \n$snapshotName = 'xxx' \n\n#Provide the name of the OS disk that will be created using the snapshot \n$osDiskName = 'xxx'\n\n#Provide the name of the Nic\n$nicName = 'xxx'\n\n#Provide the name of the VM\n$myvm = 'xxx'\n\n#Provide the VM Size\n$vmsize = 'xxx'\n\n##########\n\n$snapshot = Get-AzSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName \n\n$diskConfig = New-AzDiskConfig -Location $snapshot.Location -SourceResourceId $snapshot.Id -CreateOption Copy \n\n$disk = New-AzDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $osDiskName \n\n$nic = Get-AzNetworkInterface -Name $nicName\n\n# If AvailabilitySet is configured\n$ava = Get-AzAvailabilitySet -ResourceGroupName $resourceGroupName\n$vm = New-AzVMConfig -VMSize $vmsize -VMName $myvm -AvailabilitySetId $ava.Id\n\n## If AvailabilitySet is NOT configured\n#$vm = New-AzVMConfig -VMSize $vmsize -VMName $myvm\n\n# Set the VM configuration to point to the new disk   \nSet-AzVMOSDisk -VM $vm -ManagedDiskId $disk.Id -Name $disk.Name -CreateOption Attach -Windows\n\nAdd-AzVMNetworkInterface -VM $vm -ID $nic.Id\n\nNew-AzVM -ResourceGroupName $resourceGroupName -VM $vm -Location $disk.Location<\/pre>\n<p>7. Set Auto-Shutdown if necessary<\/p>\n<p><strong>Reference<\/strong> :<\/p>\n<p>Restoring via PowerShell<\/p>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/backup\/backup-azure-vms-automation\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/docs.microsoft.com\/en-us\/azure\/backup\/backup-azure-vms-automation<\/a><\/p>\n<p>Create a virtual machine using an existing managed OS disk with PowerShell<\/p>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/virtual-machines\/scripts\/virtual-machines-windows-powershell-sample-create-vm-from-managed-os-disks?toc=%2fpowershell%2fmodule%2ftoc.json\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/docs.microsoft.com\/en-us\/azure\/virtual-machines\/scripts\/virtual-machines-windows-powershell-sample-create-vm-from-managed-os-disks?toc=%2fpowershell%2fmodule%2ftoc.json<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Steps to restore AzureRM VM<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/kswp01.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/posts\/195"}],"collection":[{"href":"https:\/\/kswp01.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kswp01.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kswp01.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kswp01.azurewebsites.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=195"}],"version-history":[{"count":17,"href":"https:\/\/kswp01.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/posts\/195\/revisions"}],"predecessor-version":[{"id":310,"href":"https:\/\/kswp01.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/posts\/195\/revisions\/310"}],"wp:attachment":[{"href":"https:\/\/kswp01.azurewebsites.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kswp01.azurewebsites.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kswp01.azurewebsites.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}