如何为 Azure Sql 数据库弹性池中的所有数据库设置 PITR?
How to set PITR for all databases in a Azure Sql Database Elastic Pool?
我想我 运行 正在解决版本问题,因为我想要的 cmdlet 似乎只在 AzureRM.Sql
模块版本 4.7.0-preview
.
中可用
我想将弹性池中许多数据库的 PITR 保留策略设置为 35 天。默认情况下,我的 vCore 池有 7 天的保留策略,这还不够。我有数百个数据库,因此需要使用 PowerShell 来设置它们。
如果我获取要使用 Get-AzureRmSqlElasticPoolDatabase
更新的数据库列表,然后尝试 运行 Set-AzureRmSqlDatabaseBackupShortTermRetentionPolicy
我在 运行 更新后者时出现此错误:
import-module : The following error occurred while loading the extended type data file: Error in TypeData "Microsoft.Azure.Commands.Sql.Replication.Model.AzureSqlDatabaseCopyModel": The member DefaultDisplayPropertySet is already present.
Error in TypeData "Microsoft.Azure.Commands.Sql.Replication.Model.AzureReplicationLinkModel": The member DefaultDisplayPropertySet is already present.
At line:1 char:1
+ import-module azurerm.sql
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Import-Module], RuntimeException
+ FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand
我试过的东西
我试过删除模块并重新导入它。同样的错误。
我尝试导入所需版本的模块并使用第一个命令获取数据库列表,但随后出现此错误:
Get-AzureRmSqlElasticPoolDatabase : The 'Get-AzureRmSqlElasticPoolDatabase' command was found in the module 'AzureRM.Sql', but the module could not be loaded. For more information, run 'Import-Module AzureRM.Sql'.
At line:1 char:8
+ $dbs = Get-AzureRmSqlElasticPoolDatabase -ElasticPoolName $settings.E ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-AzureRmSqlElasticPoolDatabase:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
如果我使用 import-module azurerm.sql
导入 AzureRm 模块,我会收到此错误:
import-module : The following error occurred while loading the extended type data file: Error in TypeData "Microsoft.Azure.Commands.Sql.Replication.Model.AzureSqlDatabaseCopyModel": The member DefaultDisplayPropertySet is already present.
Error in TypeData "Microsoft.Azure.Commands.Sql.Replication.Model.AzureReplicationLinkModel": The member DefaultDisplayPropertySet is already present.
At line:1 char:1
+ import-module azurerm.sql
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Import-Module], RuntimeException
+ FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand
模块
Get-Module AzureRm -ListAvailable | select Name, Version
:
Name Version
---- -------
AzureRM 6.10.0
Get-Module AzureRm.Sql -ListAvailable | select Name, Version
:
Name Version
---- -------
AzureRM.Sql 4.11.5
AzureRM.Sql 4.7.0
AzureRM.Sql 4.4.0
$PSVersionTable
:
Name Value
---- -----
PSVersion 5.1.17134.228
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17134.228
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
关于如何让它工作有什么想法吗?
您可以尝试安装 4.11.4-preview
版本的 AzureRM.Sql
模块,参考此 link,在 powershell 管理员环境中使用 Install-Module -Name AzureRM.Sql -RequiredVersion 4.11.4-preview -AllowPrerelease
。
安装后无需导入模块,直接执行命令即可。如果你想检查模块是否安装成功,导航到 C:\Program Files\WindowsPowerShell\Modules\AzureRM.Sql
,你会找到一个 4.11.4
文件夹。
然后尝试示例命令为弹性池中的所有数据库设置 PITR,它在我这边工作正常。(您可以执行 Get-Help Set-AzureRmSqlDatabaseBackupShortTermRetentionPolicy
以获取命令的用法)
$dbs = Get-AzureRmSqlElasticPoolDatabase -ResourceGroupName "joywebapp" -ServerName "joydb" -ElasticPoolName "joyelastic"
foreach($db in $dbs){
Set-AzureRmSqlDatabaseBackupShortTermRetentionPolicy -ResourceGroupName $db.ResourceGroupName -ServerName $db.ServerName -DatabaseName $db.DatabaseName -RetentionDays 35
}
我想我 运行 正在解决版本问题,因为我想要的 cmdlet 似乎只在 AzureRM.Sql
模块版本 4.7.0-preview
.
我想将弹性池中许多数据库的 PITR 保留策略设置为 35 天。默认情况下,我的 vCore 池有 7 天的保留策略,这还不够。我有数百个数据库,因此需要使用 PowerShell 来设置它们。
如果我获取要使用 Get-AzureRmSqlElasticPoolDatabase
更新的数据库列表,然后尝试 运行 Set-AzureRmSqlDatabaseBackupShortTermRetentionPolicy
我在 运行 更新后者时出现此错误:
import-module : The following error occurred while loading the extended type data file: Error in TypeData "Microsoft.Azure.Commands.Sql.Replication.Model.AzureSqlDatabaseCopyModel": The member DefaultDisplayPropertySet is already present.
Error in TypeData "Microsoft.Azure.Commands.Sql.Replication.Model.AzureReplicationLinkModel": The member DefaultDisplayPropertySet is already present.
At line:1 char:1
+ import-module azurerm.sql
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Import-Module], RuntimeException
+ FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand
我试过的东西
我试过删除模块并重新导入它。同样的错误。 我尝试导入所需版本的模块并使用第一个命令获取数据库列表,但随后出现此错误:
Get-AzureRmSqlElasticPoolDatabase : The 'Get-AzureRmSqlElasticPoolDatabase' command was found in the module 'AzureRM.Sql', but the module could not be loaded. For more information, run 'Import-Module AzureRM.Sql'.
At line:1 char:8
+ $dbs = Get-AzureRmSqlElasticPoolDatabase -ElasticPoolName $settings.E ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-AzureRmSqlElasticPoolDatabase:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
如果我使用 import-module azurerm.sql
导入 AzureRm 模块,我会收到此错误:
import-module : The following error occurred while loading the extended type data file: Error in TypeData "Microsoft.Azure.Commands.Sql.Replication.Model.AzureSqlDatabaseCopyModel": The member DefaultDisplayPropertySet is already present.
Error in TypeData "Microsoft.Azure.Commands.Sql.Replication.Model.AzureReplicationLinkModel": The member DefaultDisplayPropertySet is already present.
At line:1 char:1
+ import-module azurerm.sql
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Import-Module], RuntimeException
+ FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand
模块
Get-Module AzureRm -ListAvailable | select Name, Version
:
Name Version
---- -------
AzureRM 6.10.0
Get-Module AzureRm.Sql -ListAvailable | select Name, Version
:
Name Version
---- -------
AzureRM.Sql 4.11.5
AzureRM.Sql 4.7.0
AzureRM.Sql 4.4.0
$PSVersionTable
:
Name Value
---- -----
PSVersion 5.1.17134.228
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17134.228
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
关于如何让它工作有什么想法吗?
您可以尝试安装 4.11.4-preview
版本的 AzureRM.Sql
模块,参考此 link,在 powershell 管理员环境中使用 Install-Module -Name AzureRM.Sql -RequiredVersion 4.11.4-preview -AllowPrerelease
。
安装后无需导入模块,直接执行命令即可。如果你想检查模块是否安装成功,导航到 C:\Program Files\WindowsPowerShell\Modules\AzureRM.Sql
,你会找到一个 4.11.4
文件夹。
然后尝试示例命令为弹性池中的所有数据库设置 PITR,它在我这边工作正常。(您可以执行 Get-Help Set-AzureRmSqlDatabaseBackupShortTermRetentionPolicy
以获取命令的用法)
$dbs = Get-AzureRmSqlElasticPoolDatabase -ResourceGroupName "joywebapp" -ServerName "joydb" -ElasticPoolName "joyelastic"
foreach($db in $dbs){
Set-AzureRmSqlDatabaseBackupShortTermRetentionPolicy -ResourceGroupName $db.ResourceGroupName -ServerName $db.ServerName -DatabaseName $db.DatabaseName -RetentionDays 35
}