gpt4 book ai didi

database - 使用 New-AzSqlDatabaseExport 在 powershell 中导出 azure 数据库并不总是返回 OperationStatusLink,从而导致异常

转载 作者:行者123 更新时间:2023-12-02 06:09:08 24 4
gpt4 key购买 nike

我正在编写一个 powershell 脚本,以使用 New-AzSqlDatabaseExport 命令将 Azure 数据库导出到 bacpac 文件(遵循文档 here

当我运行 powershell 脚本时,得到的结果不一致。当我打开一个新的 powershell 窗口并运行导出数据库脚本时,一切都会按预期运行,并且我会返回一个 OperationStatusLink,因此我可以在导出过程中检查导出的进度。但是,导出完成后,如果我尝试在同一窗口中第二次运行 powershell 脚本,导出将不会返回 OperationStatusLink。这将导致 Get-AzSqlDatabaseImportExportStatus 失败并出现以下异常:无法将参数绑定(bind)到参数“OperationStatusLink”,因为它为 null。

以下是重现步骤以及 powershell 脚本片段。任何关于我可以尝试确保 New-AzSqlDatabaseExport 始终返回 OperationStatusLink 的建议将不胜感激。

重现步骤:

  1. 打开 powershell 窗口

  2. 登录 Azure

  3. 运行脚本将数据库导出到 bacpac

    预期结果:导出成功并提供OperationStatusLink

    实际结果:导出成功并提供OperationStatusLink

  4. 运行脚本将数据库导出到 bacpac

    预期结果:导出成功并提供OperationStatusLink

    实际结果:导出成功,未提供OperationStatusLink

Powershell 脚本:

Connect-AzAccount
Select-AzSubscription -SubscriptionName 'subscription name'

BackupAzureDatabase.ps1 `
-DatabaseName "testDB" `
-ResourceGroupName "group1" `
-ServerName "testserver" `
-serverAdmin "admin" `
-serverPassword "********" `

备份AzureDatabase.ps1:

Param(
[string][Parameter(Mandatory=$true)] $DatabaseName,
[string][Parameter(Mandatory=$true)] $ResourceGroupName,
[string][Parameter(Mandatory=$true)] $ServerName,
[string][Parameter(Mandatory=$true)] $ServerAdmin,
[string][Parameter(Mandatory=$true)] $ServerPassword,
)
Process{
# some code to get the storage info and credentials

$ExportRequest = New-AzSqlDatabaseExport `
-ResourceGroupName $ResourceGroupName `
-ServerName $ServerName `
-DatabaseName $DatabaseName `
-StorageKeytype $StorageKeytype `
-StorageKey $PrimaryKey `
-StorageUri $BacpacUri `
-AdministratorLogin $Creds.UserName `
-AdministratorLoginPassword $Creds.Password

$ExportStatus = Get-AzSqlDatabaseImportExportStatus `
-OperationStatusLink $ExportRequest.OperationStatusLink

# Get-AzSqlDatabaseImportExportStatus throws an exception, since OperationStatusLink is empty/null most of the time
}

最佳答案

这似乎是 2.10.0 中引入的 Az.Sql 模块的回归,并且在当前版本 (2.11.0) 中仍然有效

症状:启动导出操作时引发以下异常:New-AzSqlDatabaseExport:缺少 ImportExport 操作所需的“networkIsolation”参数。

问题:这应该是可选参数,并且参数名称不正确,应该是 -UseNetworkIsolation。

解决方法:将您的脚本定位到旧版本的模块,2.9.1 似乎没问题。

长期解决方案:修复已提交,应该会在模块的下一个版本中提供。

信息来源: https://github.com/Azure/azure-powershell/issues/13097

更新2020-11-04该模块的最新版本已经包含修复程序。(2.11.1) https://www.powershellgallery.com/packages/Az/5.0.0

关于database - 使用 New-AzSqlDatabaseExport 在 powershell 中导出 azure 数据库并不总是返回 OperationStatusLink,从而导致异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64267694/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com