powershell - 为什么我的 Azure Powershell Runbook 在按计划执行时会挂起?如何防止重试?

标签 powershell azure google-drive-api azure-runbook

我对 Azure 自动化 Runbook 非常陌生,但我一直在编写一个 powershell 脚本,该脚本将 SQL Azure 数据库备份到 bacpac 文件到 blob 存储容器,然后将其上传到 Google Drive 进行“异地”备份。我已经实现了此功能,因为 1 个月前 Microsoft 意外终止了我的 Azure 订阅,我无法访问我的数据库备份,因为它们是帐户的一部分。

编写完脚本后,我成功地使用了测试功能,该功能出色地执行了任务。随后,我配置了一个每日计划,每晚执行备份。第二天早上我发现备份方面工作成功,文件确实已发布到Google Drive,但有三份副本。 Azure 门户将该作业标记为“已暂停”,我被告知该作业失败并重试了 3 次。

我已经阅读了 Invoke-WebRequest 并怀疑它超时了,尽管文档表明默认行为是不超时。其他建议是使用“内联”脚本,但我认为这仅适用于工作流 Runbook,而不是我的特定脚本 Runbook。

我认为失败的命令是:

Write-Verbose "Uploading database to google drive using a timeout of 600 seconds..."
$uploadrequest = Invoke-WebRequest -method Post -uri $GUploadURI -body $GUploadBody -Headers $Guploadheaders -usebasicparsing -TimeoutSec 600
Write-Verbose "Uploaded database to google drive." 

但我没有收到错误通知。日志显示 Runbook 写入了详细行“将数据库上传到 google 驱动器..”,之后似乎又回到开头并重复了两次。

引入 timeoutsec 作为试验,看看我是否可以覆盖超时功能(尽管我猜测这就是问题所在)。日志没有显示后续的详细消息“已将数据库上传到谷歌驱动器”,因此很明显 WebRequest 由于某种原因失败。

作为进一步的信息,我被迫将数据库的 blob 内容读入本地临时文件,然后我必须将其读入内存,以便将其作为多部分消息发布到 Google。目前数据库大小为 16Mbytes。这可能是问题所在,因为我被告知 Runbook 对内存分配非常严格。

Write-Verbose "Creating temporary file for blob content..."
$file = New-TemporaryFile
Write-Verbose "Downloading blob content to temporary file..." 
$blob = Get-AzureStorageBlobContent -Container $container -Blob $blob -Context $storageContext -Destination $file -Force
Write-Verbose "Extracting file content as RAW"
$togoogle = Get-Content $file -Raw -ErrorAction:SilentlyContinue

我真的很感激一些关于在这里做什么的建议,以及作为奖励如何防止重试,因为我可以看到如何在 powershell runbook 中进行配置。

最佳答案

当我被同样的问题难住时,我发现了以下内容: ...add the -UseBasicParsing parameter to the Invoke-WebRequest call...

这个答案很晚了,但它希望能帮助下一个像我一样搜索的人......

关于powershell - 为什么我的 Azure Powershell Runbook 在按计划执行时会挂起?如何防止重试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48259426/

相关文章:

sharepoint - 无法卸载 Sharepoint 应用程序 - 无效状态

json - 在Powershell中从JSON转换为CSV

c# - Azure SignalR 服务 | Asp.Net 网络 API |控制台客户端

python - 允许谷歌应用程序的权限后无法连接到本地主机

powershell - 用字符串中的变音符号替换字符

powershell - 如何在Powershell中捕获System.Diagnostics.Eventing.Reader错误

azure - PowerShell错误: Set-AzureDeployment : CurrentStorageAccountName is not set

sql - 无法删除 Azure SQL 托管实例资源

coldfusion - 使用 ColdFusion 将文件上传到 Google Drive

google-drive-api - Google Drive Realtime 和 Angular 魔法