问题
I think I'm running into version issues because the cmdlet I want seems to only be available in AzureRM.Sql
module version 4.7.0-preview
.
I want to set the PITR retention policy for many databases in an elastic pool to 35 days. By default my vCore pool has a retention policy of 7 days which is not enough. I have hundreds of databases so need to set them all with PowerShell.
If I get the list of databases to update with Get-AzureRmSqlElasticPoolDatabase
and then try to run Set-AzureRmSqlDatabaseBackupShortTermRetentionPolicy
I get this error when running the latter:
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
Things I've tried
I've tried removing the module and re-importing it. Same error. I've tried importing the required version of the module and getting the database list with the first command but I then get this error:
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
If I import the AzureRm module with import-module azurerm.sql
I get this error:
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
Modules
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
Any ideas on how to get this working?
回答1:
You could try to install 4.11.4-preview
version of AzureRM.Sql
module, refer to this link, use Install-Module -Name AzureRM.Sql -RequiredVersion 4.11.4-preview -AllowPrerelease
in the powershell administrator environment.
After installing it, no need to import module, you could excute the command straightly. If you want to check the module if installs successfully, navigate to C:\Program Files\WindowsPowerShell\Modules\AzureRM.Sql
, you will find a 4.11.4
folder.
Then try the sample command to set PITR for all databases in a Elastic Pool , it works fine on my side.(You could execute Get-Help Set-AzureRmSqlDatabaseBackupShortTermRetentionPolicy
to get the usage of the command)
$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
}
来源:https://stackoverflow.com/questions/52879213/how-to-set-pitr-for-all-databases-in-a-azure-sql-database-elastic-pool