Created
July 24, 2026 16:20
-
-
Save rishic5i/7367e702632f708ec7a35bdad480b2fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Requires -Version 5.1 | |
| Set-StrictMode -Version Latest | |
| $ErrorActionPreference = "Stop" | |
| $StorageAccounts = @( | |
| "blobvirtualpersona", | |
| "syncbillblob" | |
| ) | |
| $Stamp = Get-Date -Format "yyyyMMdd_HHmmss" | |
| $BackupRoot = Join-Path $env:USERPROFILE "blob_backup_$Stamp" | |
| New-Item -ItemType Directory -Path $BackupRoot -Force | Out-Null | |
| # azcopy tuning — AUTO scales to available bandwidth | |
| $env:AZCOPY_CONCURRENCY_VALUE = "AUTO" | |
| $env:AZCOPY_BUFFER_GB = "4" | |
| $env:AZCOPY_LOG_LOCATION = Join-Path $BackupRoot "_azcopy_logs" | |
| $env:AZCOPY_JOB_PLAN_LOCATION = Join-Path $BackupRoot "_azcopy_plans" | |
| New-Item -ItemType Directory -Path $env:AZCOPY_LOG_LOCATION -Force | Out-Null | |
| New-Item -ItemType Directory -Path $env:AZCOPY_JOB_PLAN_LOCATION -Force | Out-Null | |
| $Expiry = (Get-Date).ToUniversalTime().AddHours(4).ToString("yyyy-MM-ddTHH:mmZ") | |
| Write-Host "===========================================" | |
| Write-Host "Downloading blobs" | |
| Write-Host "Destination: $BackupRoot" | |
| Write-Host "Started at: $(Get-Date)" | |
| Write-Host "===========================================" | |
| foreach ($SA in $StorageAccounts) { | |
| Write-Host "" | |
| Write-Host "======================================================" | |
| Write-Host "Storage Account: $SA" | |
| Write-Host "======================================================" | |
| $Key = az storage account keys list ` | |
| --account-name $SA ` | |
| --query "[0].value" ` | |
| -o tsv 2>$null | |
| if ([string]::IsNullOrWhiteSpace($Key)) { | |
| Write-Host "Could not retrieve key for $SA. Skipping." | |
| continue | |
| } | |
| Write-Host "Key retrieved." | |
| # account-level SAS: blob service, service+container+object, read+list | |
| $Sas = az storage account generate-sas ` | |
| --account-name $SA ` | |
| --account-key $Key ` | |
| --services b ` | |
| --resource-types sco ` | |
| --permissions rl ` | |
| --expiry $Expiry ` | |
| -o tsv 2>$null | |
| if ([string]::IsNullOrWhiteSpace($Sas)) { | |
| Write-Host "Could not generate SAS for $SA. Skipping." | |
| continue | |
| } | |
| $Dest = Join-Path $BackupRoot $SA | |
| New-Item -ItemType Directory -Path $Dest -Force | Out-Null | |
| azcopy copy ` | |
| "https://$SA.blob.core.windows.net?$Sas" ` | |
| $Dest ` | |
| --recursive ` | |
| --overwrite=ifSourceNewer ` | |
| --check-length=true ` | |
| --preserve-last-modified-time ` | |
| --log-level=INFO | |
| if ($LASTEXITCODE -ne 0) { | |
| Write-Host "azcopy exited with code $LASTEXITCODE for $SA" | |
| } | |
| Write-Host "Finished $SA" | |
| } | |
| Write-Host "" | |
| Write-Host "===========================================" | |
| Write-Host "Backup completed." | |
| Write-Host "Location: $BackupRoot" | |
| Write-Host "azcopy logs: $($env:AZCOPY_LOG_LOCATION)" | |
| Write-Host "Finished at: $(Get-Date)" | |
| Write-Host "===========================================" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
powershell -ExecutionPolicy Bypass -File .\download_hades_azcopy.ps1