共用方式為


使用 PowerShell 對具有單一寫入區域的 Azure Cosmos DB 帳戶變更容錯移轉優先順序或觸發容錯移轉

適用於:NoSQL MongoDB Cassandra Gremlin Table

注意

建議您使用 Azure Az PowerShell 模組來與 Azure 互動。 若要開始使用,請參閱 安裝 Azure PowerShell。 若要了解如何移轉至 Az PowerShell 模組,請參閱將 Azure PowerShell 從 AzureRM 移轉至 Az

此範例需要 Azure PowerShell Az 5.4.0 或更新版本。 執行 Get-Module -ListAvailable Az 可查看已安裝的版本。 如果您需要安裝,請參閱安裝 Azure PowerShell 模組

執行 Connect-AzAccount 來登入 Azure。

範例指令碼

注意

failoverPriority=0 的區域進行任何變更都會觸發手動容錯移轉,而且只能對設定為手動容錯移轉的帳戶進行。 所有其他區域的變更只會變更 Azure Cosmos DB 帳戶的容錯移轉優先順序。

注意

此範例示範如何使用 API for NoSQL 帳戶。 若要針對其他 API 使用此範例,請複製相關的屬性,並套用至您的 API 專屬指令碼

# Reference: Az.CosmosDB | https://docs.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Update Cosmos DB account: Change region failover priority.
# Note: updating location at priority 0 triggers a failover to the new location
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$resourceGroupName = "myResourceGroup" # Resource Group must already exist
$accountName = "myaccount" # Must be all lower case
$locations = @("West US", "East US") # Regions ordered by UPDATED failover priority
# --------------------------------------------------

# Get existing Cosmos DB account
$account = Get-AzCosmosDBAccount -ResourceGroupName $resourceGroupName -Name $accountName

# Update account failover priority
Update-AzCosmosDBAccountFailoverPriority -InputObject $account -FailoverPolicy $locations

清除部署

在執行過指令碼範例之後,您可以使用下列命令來移除資源群組和所有與其相關聯的資源。

Remove-AzResourceGroup -ResourceGroupName "myResourceGroup"

指令碼說明

此指令碼會使用下列命令。 下表中的每個命令都會連結至命令特定的文件。

Command 注意
Azure Cosmos DB
Get-AzCosmosDBAccount 列出 Azure Cosmos DB 帳戶,或取得指定的 Azure Cosmos DB 帳戶。
Update-AzCosmosDBAccountFailoverPriority 更新 Azure Cosmos DB 帳戶區域的容錯移轉優先順序。
Azure 資源群組
Remove-AzResourceGroup 刪除資源群組,包括所有的巢狀資源。

下一步

如需有關 Azure PowerShell 的詳細資訊,請參閱 Azure PowerShell 文件