我正在努力设置一个运行手册,以便一夜之间将我的 REDIS Premium 数据导出到 BLOB 容器。这可能是因为我缺乏 Powershell 经验。
到目前为止我想到了这个:
# Ensures you do not inherit an AzContext in your runbook
Disable-AzContextAutosave -Scope Process
# Connect to Azure with system-assigned managed identity
$AzureContext = (Connect-AzAccount -Identity).context
# Set and store context
$AzureContext = Set-AzContext -SubscriptionName $AzureContext.Subscription -DefaultProfile $AzureContext
# Import Azure Modules
Import-Module Az.Accounts
Import-Module Az.RedisCache
$RedisResourceGroupName = Get-AutomationVariable -Name 'RedisResourceGroupName'
$RedisStorageName = Get-AutomationVariable -Name 'RedisStorageName'
$RedisExportDataContainerUrl = Get-AutomationVariable -Name 'RedisExportDataContainerUrl'
$EpochTimeStamp = Get-Date -UFormat %s
$BlobPrefix = $EpochTimeStamp + "_"
$exportOutput = Export-AzRedisCache -ResourceGroupName $RedisResourceGroupName -Name $RedisStorageName -Prefix $BlobPrefix -Container $RedisExportDataContainerUrl #-PreferredDataArchiveAuthMethod ManagedIdentity
Write-Output $exportOutput
两个问题:
为了不是抛出 Forbidden 错误,我将 AutomationAccount 的托管标识添加到 Owner-role。其他角色似乎没有足够的权限。这是唯一的方法吗?
该脚本花费了很长时间(12GB 的数据),但最终出现了此错误消息
Export-AzRedisCache : Long running operation failed with status 'Conflict'. At line:20 char:17 + ... ortOutput = Export-AzRedisCache -ResourceGroupName $RedisResourceGrou ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Export-AzRedisCache], CloudException + FullyQualifiedErrorId: Microsoft.Azure.Commands.RedisCache.ExportAzureRedisCache