PowerShell을 사용하여 Azure Cosmos DB 계정의 지역 업데이트

적용 대상: NoSQL MongoDB Cassandra Gremlin 테이블

이 PowerShell 스크립트는 Azure Cosmos DB 계정에서 사용하는 Azure 지역을 업데이트합니다. 이 스크립트를 사용하여 Azure 지역을 추가하거나 지역 장애 조치(failover) 순서를 변경할 수 있습니다.

참고 항목

Azure Az PowerShell 모듈을 사용하여 Azure와 상호 작용하는 것이 좋습니다. 시작하려면 Azure PowerShell 설치를 참조하세요. Az PowerShell 모듈로 마이그레이션하는 방법에 대한 자세한 내용은 Azure PowerShell을 AzureRM에서 Azure로 마이그레이션을 참조하세요.

필수 조건

  • Azure 리소스 그룹에 기존 Azure Cosmos DB 계정이 필요합니다.

  • 스크립트에는 Azure PowerShell Az 5.4.0 이상이 필요합니다. Get-Module -ListAvailable Az를 실행하여 설치된 버전을 나열합니다. PowerShell을 설치해야 하는 경우 Azure PowerShell 모듈 설치를 참조하세요.

  • Connect-AzAccount를 실행하여 Azure에 로그인합니다.

샘플 스크립트

Update-AzCosmosDBAccountRegion 명령은 Azure Cosmos DB 계정에 대한 Azure 지역을 업데이트합니다. 이 명령에는 리소스 그룹 이름, Azure Cosmos DB 계정 이름 및 원하는 장애 조치(failover) 순서의 Azure 지역 목록이 필요합니다.

이 스크립트에서 Get-AzCosmosDBAccount 명령은 지정한 Azure Cosmos DB 계정을 가져옵니다. New-AzCosmosDBLocationObjectPSLocation 형식의 개체를 만듭니다. Update-AzCosmosDBAccountRegionPSLocation 매개 변수를 사용하여 계정 지역을 업데이트합니다.

  • 지역을 추가하는 경우 동일한 작업에서 첫 번째 장애 조치(failover) 지역을 변경하지 마세요. 별도의 작업에서 장애 조치(failover) 우선 순위를 변경합니다.
  • 다른 Azure Cosmos DB 계정 속성을 변경하는 것과 동일한 작업에서 지역을 수정할 수 없습니다. 이러한 작업은 별도로 수행하세요.

이 샘플은 API for NoSQL 계정을 사용합니다. 이 샘플을 다른 API에 사용하려면 관련 속성을 복사하고 API별 스크립트에 적용합니다.

# Reference: Az.CosmosDB | https://docs.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Update Cosmos DB account: Add an Azure region (location)
# NOTE: if adding a region to a single master account, do not change the first 
# region in the same operation. Change failover priority order in a
# separate operation.
# NOTE: this operation will return, but account updates may still be
# occurring. Check the account or Resource Group's activity log for status.
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$resourceGroupName = "myResourceGroup" # Resource Group must already exist
$accountName = "myaccount" # Must be all lower case

# Regions ordered by failover priority, with each indicating whether AZ-enabled
# Region AZ status can be checked at https://azure.microsoft.com/global-infrastructure/regions/
$locations = @(
    @{name = "East US"; azEnabled = $true};
    @{name = "West US"; azEnabled = $false};
)
# --------------------------------------------------

Write-Host "Get Cosmos DB account"
$account = Get-AzCosmosDBAccount -ResourceGroupName $resourceGroupName -Name $accountName

$i = 0
$locationObjects = @()

ForEach ($location in $locations) {
    $locationObjects += New-AzCosmosDBLocationObject -LocationName $location.name -IsZoneRedundant $location.azEnabled -FailoverPriority ($i++)
}

Write-Host "Update Cosmos DB account region(s)"
Update-AzCosmosDBAccountRegion -InputObject $account -LocationObject $locationObjects

스크립트가 결과를 반환하더라도 업데이트 작업이 완료되지 않을 수 있습니다. Azure Cosmos DB 계정 활동 로그를 사용하여 Azure Portal에서 작업의 상태를 확인합니다.

Azure 리소스 그룹 삭제

Azure Cosmos DB 계정을 삭제하려는 경우 Remove-AzResourceGroup PowerShell 명령을 사용하여 해당 리소스 그룹을 제거할 수 있습니다. 이 명령은 Azure Cosmos DB 계정과 해당 컨테이너 및 데이터베이스를 포함하여 Azure 리소스 그룹과 그 안의 모든 리소스를 제거합니다.

Remove-AzResourceGroup -ResourceGroupName "myResourceGroup"

다음 단계