如何为Azure Sql数据库弹性池中的所有数据库设置PITR? [英] How to set PITR for all databases in a Azure Sql Database Elastic Pool?

查看:107
本文介绍了如何为Azure Sql数据库弹性池中的所有数据库设置PITR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我遇到了版本问题,因为我想要的cmdlet似乎仅在AzureRM.Sql模块版本4.7.0-preview中可用.

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.

我想将弹性池中许多数据库的PITR保留策略设置为35天.默认情况下,我的vCore池的保留策略为7天,这还不够.我有数百个数据库,因此需要使用PowerShell设置它们.

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.

如果我获取要用Get-AzureRmSqlElasticPoolDatabase更新的数据库列表,然后尝试运行Set-AzureRmSqlDatabaseBackupShortTermRetentionPolicy,则在运行后者时会出现此错误:

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

我尝试过的事情

我尝试删除该模块并重新导入它.同样的错误. 我尝试导入所需版本的模块,并使用第一个命令获取数据库列表,但随后出现此错误:

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

如果使用import-module azurerm.sql导入AzureRm模块,则会出现此错误:

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

模块

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?

推荐答案

您可以尝试安装AzureRM.Sql模块的4.11.4-preview版本,请参考此

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.

安装后,无需导入模块,可以直接执行命令.如果要检查模块是否安装成功,请导航到C:\Program Files\WindowsPowerShell\Modules\AzureRM.Sql,您将找到一个4.11.4文件夹.

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.

然后尝试使用示例命令为弹性池中的所有数据库设置PITR,这对我来说效果很好.(您可以执行Get-Help Set-AzureRmSqlDatabaseBackupShortTermRetentionPolicy来获取命令的用法)

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
}

这篇关于如何为Azure Sql数据库弹性池中的所有数据库设置PITR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆