-
Notifications
You must be signed in to change notification settings - Fork 0
/
az-steps-6-download.ps1
68 lines (55 loc) · 2.07 KB
/
az-steps-6-download.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Reference:
# https://learn.microsoft.com/en-us/cli/azure/storage/blob?view=azure-cli-latest#az-storage-blob-list
# https://learn.microsoft.com/en-us/cli/azure/storage/blob?view=azure-cli-latest#az-storage-blob-download
# Source the initialization script.
. ./az-steps-0-init.ps1
$beginTime = LogRunBegin "az-steps-6-download"
Say "`nSTEP - Preparing to download from blob storage.`n"
# Get the storage account key.
$storageKey = $(az storage account keys list -g $opts.rgName -n $opts.storageAcctName --query '[0].value' -o tsv)
$blobNames = az storage blob list `
--account-name $opts.storageAcctName `
--account-key $storageKey `
--container-name $opts.containerPrivate `
--query '[].name' -o tsv
# Download the compiled executable file built on the VM.
$downloadFileName = $opts.outputFileName
$downloadDest = [IO.Path]::Combine($opts.downloadPath, $downloadFileName)
if ($blobNames -contains $downloadFileName) {
if (Test-Path $downloadDest) {
Say "`nRemove existing '$downloadDest'`n"
Remove-Item $downloadDest
}
Say "`nDownloading '$downloadFileName'`n"
$result = az storage blob download `
--account-name $opts.storageAcctName `
--account-key $storageKey `
--file $downloadDest `
--container-name $opts.containerPrivate `
--name $downloadFileName
$result | Out-Null
}
else {
Yell "Blob not found: $downloadFileName"
}
# Download the log file from the VM.
$downloadFileName = $opts.outputLogName
$downloadDest = [IO.Path]::Combine($opts.downloadPath, $downloadFileName)
if ($blobNames -contains $downloadFileName) {
if (Test-Path $downloadDest) {
Say "`nRemove existing '$downloadDest'`n"
Remove-Item $downloadDest
}
Say "`nDownloading '$downloadFileName'`n"
$result = az storage blob download `
--account-name $opts.storageAcctName `
--account-key $storageKey `
--file $downloadDest `
--container-name $opts.containerPrivate `
--name $downloadFileName
$result | Out-Null
}
else {
Yell "Blob not found: $downloadFileName"
}
LogRunEnd "az-steps-6-download" $beginTime