Daily Azure: Migrate a Storge Account
Inhaltsverzeichnis
TL;DR
Migration is done via azcopy:
- download souce container to local folder
- upload local folder to destination container
Get AzCopy
Here is the script install-azcopy.ps1
:
# Download and extract # $URI = "https://aka.ms/downloadazcopy-v10-windows" $DST = "~\AppData\Local\Programs\AZCopy\" Invoke-WebRequest -Uri $URI -OutFile AzCopy.zip -UseBasicParsing Expand-Archive ./AzCopy.zip ./AzCopy -Force # Move AzCopy mkdir ~\AppData\Local\Programs\AZCopy Get-ChildItem ./AzCopy/*/azcopy.exe | Move-Item -Destination "~\$DEST" # Add AzCopy to PATH $userenv = (Get-ItemProperty -Path 'HKCU:\Environment' -Name Path).path $newPath = "$userenv New-ItemProperty -Path 'HKCU:\Environment' -Name Path -Value $newPath -Force # Clean the kitchen del -Force AzCopy.zip del -Force -Recurse .\AzCopy\
Copy Folder
param ( $FOLDER = "", [Parameter(Mandatory=$false)] [string]$TYPE = "latest", [Parameter(Mandatory=$false)] [switch]$LOGIN ) if ($TYPE -eq "latest") { $SRC_ROOT="<latest-folder>" $DST_ROOT="latest" } else { $SRC_ROOT="<history-folder>" $DST_ROOT="history" } $SRC_ACCCOUNT = "<source storage account>"; $DST_ACCCOUNT = "<destination storage account>"; $SRC_CONTAINER = "<source container>" $DST_CONTAINER = "<destination container>" $SRC_URL = "https://${SRC_ACCCOUNT}.blob.core.windows.net/$SRC_CONTAINER/$SRC_ROOT/$FOLDER/" $DST_URL = "https://${DST_ACCCOUNT}.blob.core.windows.net/$DST_CONTAINER/$DST_ROOT/" $TMP_FLDR = "C:\TMP\Downloads" Write-Host "== Copy '$FOLDER'" Write-Host " from $SRC_URL" Write-Host " to $DST_URL" # if ($LOGIN) { $ENV:AZCOPY_CRED_TYPE = "OAuthToken"; $ENV:AZCOPY_CONCURRENCY_VALUE = "AUTO"; azcopy login } Write-Host "== Download ======================================================" Write-Host " from $SRC_URL" Write-Host " to $TMP_FLDR\$CONTAINER" azcopy copy $SRC_URL ` $TMP_FLDR ` --trusted-microsoft-suffixes=${SRC_ACCCOUNT}.blob.core.windows.net ` --overwrite=true ` --check-md5=FailIfDifferent ` --from-to=BlobLocal ` --recursive ` --log-level=ERROR # Upload Write-Host "== Upload ======================================================" Write-Host " from $TMP_FLDR\$CONTAINER" Write-Host " to $DST_URL" azcopy copy $TMP_FLDR\$CONTAINER ` $DST_URL ` --overwrite=true ` --from-to=LocalBlob ` --blob-type BlockBlob ` --follow-symlinks ` --check-length=true ` --put-md5 ` --follow-symlinks ` --disable-auto-decoding=false ` --recursive ` --log-level=ERROR
Call the script
First call should use -login to authenticate
.\copy.ps1 demo-folder-1 -login
Then, following commands dont need the login
.\copy.ps1 demo-folder-2
Leave a Reply