使用新AzSqlDatabaseExport在powershell中导出azure数据库并不总是返回OperationStatusLink,从而导致异常
我正在编写一个powershell脚本,以使用新的AzSqlDatabaseExport命令(遵循文档)将Azure数据库导出到bacpac文件 当我运行powershell脚本时,得到的结果不一致。当我打开一个新的powershell窗口并运行导出数据库脚本时,所有内容都按预期运行,并且我得到一个OperationStatusLink,因此我可以在导出过程中检查导出进度。但是,一旦导出完成,如果我尝试运行powershell脚本在同一窗口内第二次,导出将不会返回OperationStatusLink。这将导致Get-AzSqlDatabaseImportExportStatus失败,出现以下异常:无法将参数绑定到参数“OperationStatusLink”,因为它为null 下面是复制的步骤,以及powershell脚本的一个片段。对于如何确保新AzSqlDatabaseExport始终返回OperationStatusLink,我将不胜感激 复制步骤:使用新AzSqlDatabaseExport在powershell中导出azure数据库并不总是返回OperationStatusLink,从而导致异常,database,azure,powershell,bacpac,Database,Azure,Powershell,Bacpac,我正在编写一个powershell脚本,以使用新的AzSqlDatabaseExport命令(遵循文档)将Azure数据库导出到bacpac文件 当我运行powershell脚本时,得到的结果不一致。当我打开一个新的powershell窗口并运行导出数据库脚本时,所有内容都按预期运行,并且我得到一个OperationStatusLink,因此我可以在导出过程中检查导出进度。但是,一旦导出完成,如果我尝试运行powershell脚本在同一窗口内第二次,导出将不会返回OperationStatusL
Connect-AzAccount
Select-AzSubscription -SubscriptionName 'subscription name'
BackupAzureDatabase.ps1 `
-DatabaseName "testDB" `
-ResourceGroupName "group1" `
-ServerName "testserver" `
-serverAdmin "admin" `
-serverPassword "********" `
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
}
Connect-AzAccount
Select-AzSubscription -SubscriptionName 'subscription name'
BackupAzureDatabase.ps1 `
-DatabaseName "testDB" `
-ResourceGroupName "group1" `
-ServerName "testserver" `
-serverAdmin "admin" `
-serverPassword "********" `
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
}
BackupAzureDatabase.ps1:
Connect-AzAccount
Select-AzSubscription -SubscriptionName 'subscription name'
BackupAzureDatabase.ps1 `
-DatabaseName "testDB" `
-ResourceGroupName "group1" `
-ServerName "testserver" `
-serverAdmin "admin" `
-serverPassword "********" `
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似乎可以 长期解决方案: 修复程序已提交,应在模块的下一版本中提供 信息来源: 更新2020-11-04 模块的最新版本已包含修复程序。 (2.11.1)
有点奇怪,我尝试了同一个脚本,它在我这边运行得很好。我无法重现错误。我会看看是否能让它正常工作。谢谢。我在本地机器上升级了AZ模块,现在一切正常。