{"id":8695,"date":"2025-04-02T01:58:14","date_gmt":"2025-04-02T01:58:14","guid":{"rendered":"https:\/\/pariswells.com\/blog\/?p=8695"},"modified":"2025-04-02T01:58:15","modified_gmt":"2025-04-02T01:58:15","slug":"install-azcopy-and-copy-vhd-from-one-region-to-another-in-azure","status":"publish","type":"post","link":"https:\/\/pariswells.com\/blog\/research\/install-azcopy-and-copy-vhd-from-one-region-to-another-in-azure","title":{"rendered":"Install AzCopy and Copy VHD from One Region to another in Azure"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code class=\"\"> \n#Download AzCopy\nInvoke-WebRequest -Uri \"https:\/\/aka.ms\/downloadazcopy-v10-windows\" -OutFile AzCopy.zip -UseBasicParsing\n \n#Curl.exe option (Windows 10 Spring 2018 Update (or later))\ncurl.exe -L -o AzCopy.zip https:\/\/aka.ms\/downloadazcopy-v10-windows\n \n#Expand Archive\nExpand-Archive .\/AzCopy.zip .\/AzCopy -Force\n \n#Move AzCopy to the destination you want to store it\nGet-ChildItem .\/AzCopy\/*\/azcopy.exe | Move-Item -Destination \"C:\\Scripts\\AzCopy.exe\"\n \n#Add your AzCopy path to the Windows environment PATH (C:\\Scripts\\AzCopy in this example), e.g., using PowerShell:\n$userenv = [System.Environment]::GetEnvironmentVariable(\"Path\", \"User\")\n[System.Environment]::SetEnvironmentVariable(\"PATH\", $userenv + \";C:\\Scripts\\AzCopy\", \"User\")<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">Connect-AzAccount\n\n# Name of the Managed Disk you are starting with\n$sourceDiskName = \"SQL2019EnterpriseVHD\"\n# Name of the resource group the source disk resides in\n$sourceRG = \"rg\"\n# Name you want the destination disk to have\n$targetDiskName = \"SQL2019EnterpriseASE\"\n# Name of the resource group to create the destination disk in\n$targetRG = \"rg\"\n# Azure region the target disk will be in\n$targetLocate = \"australiasoutheast\"\n \n# Gather properties of the source disk\n$sourceDisk = Get-AzDisk -ResourceGroupName $sourceRG -DiskName $sourceDiskName\n \n# Create the target disk config, adding the sizeInBytes with the 512 offset, and the -Upload flag\n# If this is an OS disk, add this property: -OsType $sourceDisk.OsType\n$targetDiskconfig = New-AzDiskConfig -SkuName 'Premium_LRS' -UploadSizeInBytes $($sourceDisk.DiskSizeBytes+512) -Location $targetLocate -CreateOption 'Upload'\n \n# Create the target disk (empty)\n$targetDisk = New-AzDisk -ResourceGroupName $targetRG -DiskName $targetDiskName -Disk $targetDiskconfig\n \n# Get a SAS token for the source disk, so that AzCopy can read it\n$sourceDiskSas = Grant-AzDiskAccess -ResourceGroupName $sourceRG -DiskName $sourceDiskName -DurationInSecond 86400 -Access 'Read'\n \n# Get a SAS token for the target disk, so that AzCopy can write to it\n$targetDiskSas = Grant-AzDiskAccess -ResourceGroupName $targetRG -DiskName $targetDiskName -DurationInSecond 86400 -Access 'Write'\n \n# Begin the copy!\n.\\azcopy copy $sourceDiskSas.AccessSAS $targetDiskSas.AccessSAS --blob-type PageBlob\n \n# Revoke the SAS so that the disk can be used by a VM\nRevoke-AzDiskAccess -ResourceGroupName $sourceRG -DiskName $sourceDiskName\n \n# Revoke the SAS so that the disk can be used by a VM\nRevoke-AzDiskAccess -ResourceGroupName $targetRG -DiskName $targetDiskName\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-8695","post","type-post","status-publish","format-standard","hentry","category-research"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/8695","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/comments?post=8695"}],"version-history":[{"count":1,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/8695\/revisions"}],"predecessor-version":[{"id":8696,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/8695\/revisions\/8696"}],"wp:attachment":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/media?parent=8695"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/categories?post=8695"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/tags?post=8695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}