Improved existing scripts in "Extras"
This commit is contained in:
Родитель
139d203b83
Коммит
bb315bcdff
|
@ -3,6 +3,7 @@
|
|||
param(
|
||||
$sourceLocation,
|
||||
$destinationLocations,
|
||||
$destinationAccountType,
|
||||
$sourceVHDName,
|
||||
$destinationVHDName,
|
||||
$customSecretsFilePath
|
||||
|
@ -41,6 +42,10 @@ else
|
|||
{
|
||||
$newVHDName = $sourceVHDName
|
||||
}
|
||||
if (!$destinationAccountType)
|
||||
{
|
||||
$destinationAccountType="Standard,Premium"
|
||||
}
|
||||
$regionName = $sourceLocation.Replace(" ","").Replace('"',"").ToLower()
|
||||
$regionStorageMapping = [xml](Get-Content .\XML\RegionAndStorageAccounts.xml)
|
||||
$sourceStorageAccountName = $regionStorageMapping.AllRegions.$regionName.StandardStorage
|
||||
|
@ -86,7 +91,7 @@ else
|
|||
{
|
||||
$targetRegions = (Get-AzureRmLocation).Location
|
||||
}
|
||||
$targetStorageAccounts = ($GetAzureRmStorageAccount | where { ( $_.StorageAccountName -imatch "konkaci" ) -and $targetRegions.Contains($_.PrimaryLocation)}).StorageAccountName
|
||||
$targetStorageAccounts = ($GetAzureRmStorageAccount | where { ( $_.StorageAccountName -imatch "konkaci" ) -and $targetRegions.Contains($_.PrimaryLocation) -and $destinationAccountType -imatch $_.Sku.Tier}).StorageAccountName
|
||||
$destContextArr = @()
|
||||
foreach ($targetSA in $targetStorageAccounts)
|
||||
{
|
||||
|
|
|
@ -62,17 +62,33 @@ $DateTimeUTC = "$($utctime.Year)-$($utctime.Month)-$($utctime.Day) $($utctime.Ho
|
|||
|
||||
try
|
||||
{
|
||||
if ($destinationStorageKey)
|
||||
{
|
||||
Write-Host "Using user provided storage account key."
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host "Getting $destinationStorageAccount storage account key..."
|
||||
$allResources = Get-AzureRmResource
|
||||
$destSARG = ($allResources | Where { $_.ResourceType -imatch "storageAccounts" -and $_.ResourceName -eq "$destinationStorageAccount" }).ResourceGroupName
|
||||
$keyObj = Get-AzureRmStorageAccountKey -ResourceGroupName $destSARG -Name $destinationStorageAccount
|
||||
$destinationStorageKey = $keyObj[0].Value
|
||||
}
|
||||
$containerName = "$destinationContainer"
|
||||
$storageAccountName = $destinationStorageAccount
|
||||
$blobContext = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $destinationStorageKey
|
||||
$uploadedFiles = @()
|
||||
foreach($fileName in $filePaths.Split(","))
|
||||
{
|
||||
$ticks = (Get-Date).Ticks
|
||||
#$fileName = "$LogDir\$($vmData.RoleName)-waagent.log.txt"
|
||||
$blobName = "$destinationFolder/$($fileName | Split-Path -Leaf)"
|
||||
Write-Host
|
||||
$out = Set-AzureStorageBlobContent -File $filename -Container $containerName -Blob $blobName -Context $blobContext -Force -ErrorAction Stop
|
||||
Write-Host "Upload file to Azure: Success: $filename"
|
||||
Write-Host "$($blobContext.BlobEndPoint)$containerName/$blobName : Success"
|
||||
$uploadedFiles += "$($blobContext.BlobEndPoint)$containerName/$blobName"
|
||||
}
|
||||
return $uploadedFiles
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -81,5 +97,5 @@ catch
|
|||
$ErrorMessage = $_.Exception.Message
|
||||
Write-Host "EXCEPTION : $ErrorMessage"
|
||||
Write-Host "Source : Line $line in script $script_name."
|
||||
Write-Host "ERROR : Uploading to $destinationStorageAccount failed."
|
||||
}
|
||||
Write-Host "ERROR : $($blobContext.BlobEndPoint)/$containerName/$blobName : Failed"
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче