연속 백업 계정에 대해 복원 가능한 최신 타임스탬프 가져오기

적용 대상: NoSQL MongoDB Gremlin 테이블

이 문서에서는 연속 백업 모드로 사용하도록 설정된 계정에 대해 복원 가능한 최신 타임스탬프를 가져오는 방법에 대해 설명합니다. Azure PowerShell 및 Azure CLI를 사용하여 복원 가능한 최신 시간을 가져오는 방법을 설명하고 PowerShell 및 CLI 명령에 대한 요청 및 응답 형식을 제공합니다.

이 기능은 Azure Cosmos DB API for NoSQL 컨테이너, API for MongoDB, Table API 및 Gremlin 그래프용 API에서 지원됩니다.

Important

다중 지역 쓰기 계정의 경우 복원 가능한 최신 타임스탬프는 충돌 해결 타임스탬프(crts)에 따라 결정됩니다. 아래 나열된 방법으로는 반환되지 않습니다. Azure Cosmos DB의 변경 피드를 사용하고 컨테이너에서 ConflictResolvedTimestamp(crts)가 포함된 문서를 반환하는 방법을 알아보려면 여기에서 GitHub 샘플을 참조하세요.

SQL 컨테이너

PowerShell

Get-AzCosmosDBSqlContainerBackupInformation -AccountName <System.String> `
  -DatabaseName <System.String> `
  [-DefaultProfile <Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer>] `
  -Location <System.String> `
  -Name <System.String> `
  -ResourceGroupName <System.String> [<CommonParameters>]

샘플 요청:

Get-AzCosmosDBSqlContainerBackupInformation -ResourceGroupName "rg" `
  -AccountName "sqlpitracc" `
  -DatabaseName "db1" `
  -Name "container1" `
  -Location "eastus"

샘플 응답(UTC 형식):

LatestRestorableTimestamp
-------------------------
10/26/2021 6:24:25 PM

CLI

az cosmosdb sql retrieve-latest-backup-time -g {resourcegroup} \
  -a {accountname} \
  -d {db_name} \
  -c {container_name} \
  -l {location}

샘플 요청:

az cosmosdb sql retrieve-latest-backup-time -g "rg" \
  -a "sqlpitracc" \
  -d "db1" \
  -c "container1" \
  -l "eastus"

샘플 응답(UTC 형식):

{
  "continuousBackupInformation": {
    "latestRestorableTimestamp": "10/26/2021 5:27:45 PM"
  }
}

SQL 데이터베이스

다음 스크립트를 사용하여 데이터베이스에 대해 복원 가능한 최신 타임스탬프를 가져옵니다. 이 스크립트는 지정된 데이터베이스 내의 모든 컨테이너를 다시 실행하고 모든 컨테이너의 복원 가능한 최신 타임스탬프를 반환합니다.

Function Get-LatestRestorableTimestampForSqlDatabase {
[CmdletBinding()]
param(
  [Parameter(Position = 0, mandatory = $true)]
  [string] $resourceGroupName,
  [Parameter(Position = 1, mandatory = $true)]
  [string] $accountName,
  [Parameter(Position = 2, mandatory = $true)]
  [string] $databaseName,
  [Parameter(Position = 3, mandatory = $true)]
  [string] $location)

Write-Host
Write-Host "Latest restorable timestamp for a database is minimum of restorable timestamps of all the underlying containers"
Write-Host

Write-Debug "Listing all containers in database: $databaseName"
$containers = Get-AzCosmosDBSqlContainer -ResourceGroupName $resourceGroupName -AccountName $accountName -DatabaseName $databaseName

If (-Not $containers) {
    throw "Error: Found no containers to restore in the given database."
}

Write-Debug "Found $($containers.Length) containers under database $databaseName"

$latestRestorableTimestampForDatabase = [DateTime]::MaxValue
foreach ($container in $containers) {
    Write-Debug "Getting latest restorable timestamp for container: $($container.Name)"

    $latestRestorableTimestampForContainer = Get-AzCosmosDBSqlContainerBackupInformation -ResourceGroupName $resourceGroupName -AccountName $accountName -DatabaseName $databaseName -Name $container.Name -Location $location

    Write-Debug "Latest Restorable Timestamp for container $($container.Name): $($latestRestorableTimestampForContainer.LatestRestorableTimestamp)"

    $latestRestorableTimestampForContainerDateTime = [DateTime]$latestRestorableTimestampForContainer.LatestRestorableTimestamp

    If ($latestRestorableTimestampForContainerDateTime -lt $latestRestorableTimestampForDatabase) {
        Write-Debug "Latest Restorable Timestamp for container $($container.Name) is less than current database restorable timestamp: $latestRestorableTimestampForDatabase"

        $latestRestorableTimestampForDatabase = $latestRestorableTimestampForContainerDateTime
    }

    Write-Debug "Latest Restorable Timestamp for database so far: $latestRestorableTimestampForDatabase"
}

if ($latestRestorableTimestampForDatabase -eq [DateTime]::MaxValue) {
    throw "Error: Failed to retrieve latest backup timestamp for database: $databaseName"
}

Write-Debug "Latest Restorable Timestamp in UTC for database $($databaseName): $latestRestorableTimestampForDatabase"

return $latestRestorableTimestampForDatabase
}

구문:

Get-LatestRestorableTimestampForSqlDatabase `
  -ResourceGroupName <resourceGroup> `
  -AccountName <accountName> `
  -DatabaseName <databaseName> `
  -Location <location>

샘플 요청:

Import-Module .\LatestRestorableDatabaseForSqlDatabase.ps1
Get-LatestRestorableTimestampForSqlDatabase `
  -ResourceGroupName rg `
  -AccountName sqlpitracc `
  -DatabaseName db1 `
  -Location eastus

샘플 응답(UTC 형식):

Latest restorable timestamp for a database is minimum of restorable timestamps of all the underlying containers
Wednesday, November 3, 2021 8:02:44 PM

SQL 계정

다음 스크립트를 사용하여 SQL 계정에 대해 복원 가능한 최신 타임스탬프를 가져옵니다. 이 스크립트는 이 계정 내의 모든 컨테이너를 다시 실행하고 모든 컨테이너의 복원 가능한 최신 최소 타임스탬프를 반환합니다.

Function Get-LatestRestorableTimestampForSqlAccount {
[CmdletBinding()]
param(
    [Parameter(Position = 0, mandatory = $true)]
    [string] $resourceGroupName,
    [Parameter(Position = 1, mandatory = $true)]
    [string] $accountName,
    [Parameter(Position = 2, mandatory = $true)]
    [string] $location)

Write-Host
Write-Host "Latest restorable timestamp for an account is minimum of restorable timestamps of all the underlying containers"
Write-Host

Write-Debug "Listing all databases in account: $accountName"

$databases = Get-AzCosmosDBSqlDatabase -ResourceGroupName $resourceGroupName -AccountName $accountName
Write-Debug "Found $($databases.Length) databases under account $accountName"

$latestRestorableTimestampForAccount = [DateTime]::MaxValue

foreach ($database in $databases) {
    Write-Debug "Listing all containers in database: $($database.Name)"
    $containers = Get-AzCosmosDBSqlContainer -ResourceGroupName $resourceGroupName -AccountName $accountName -DatabaseName $($database.Name)

    If (-Not $containers) {
        throw "Error: Found no containers to restore in the given database."
    }

    Write-Debug "Found $($containers.Length) containers under database $($database.Name)"

    foreach ($container in $containers) {
        Write-Debug "Getting latest restorable timestamp for container: $($container.Name)"

        $latestRestorableTimestampForContainer = Get-AzCosmosDBSqlContainerBackupInformation -ResourceGroupName $resourceGroupName -AccountName $accountName -DatabaseName $database.Name -Name $container.Name -Location $location

        Write-Debug "Latest Restorable Timestamp for container $($container.Name): $($latestRestorableTimestampForContainer.LatestRestorableTimestamp)"

        $latestRestorableTimestampForContainerDateTime = [DateTime]$latestRestorableTimestampForContainer.LatestRestorableTimestamp

        If ($latestRestorableTimestampForContainerDateTime -lt $latestRestorableTimestampForAccount) {
            Write-Debug "Latest Restorable Timestamp for container $($container.Name) is less than current database restorable timestamp: $latestRestorableTimestampForAccount"

            $latestRestorableTimestampForAccount = $latestRestorableTimestampForContainerDateTime
        }

        Write-Debug "Latest Restorable Timestamp for database so far: $latestRestorableTimestampForAccount"
    }
}

if ($latestRestorableTimestampForAccount -eq [DateTime]::MaxValue) {
    throw "Error: Failed to retrieve latest backup timestamp for account: $accountName"
}
    
Write-Debug "Latest Restorable Timestamp in UTC for account $($accountName): $latestRestorableTimestampForAccount"

return $latestRestorableTimestampForAccount
}

구문:

Get-LatestRestorableTimestampForSqlAccount `
  -ResourceGroupName <resourceGroupName> `
  -AccountName <accountName> `
  -Location <location>

샘플 요청:

Import-Module .\LatestRestorableTimestampForSqlAccount.ps1

Get-LatestRestorableTimestampForSqlAccount `
  -ResourceGroupName rg `
  -AccountName sqlpitracc `
  -location eastus

샘플 응답(UTC 형식):

Latest restorable timestamp for an account is minimum of restorable timestamps of all the underlying containers
Wednesday, November 3, 2021 8:11:03 PM

MongoDB 컬렉션

PowerShell

Get-AzCosmosDBMongoDBCollectionBackupInformation `
  -AccountName <System.String> `
  -DatabaseName <System.String> `
  [-DefaultProfile <Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer>] `
  -Location <System.String> `
  -Name <System.String> `
  -ResourceGroupName <System.String> [<CommonParameters>]

샘플 요청:

Get-AzCosmosDBMongoDBCollectionBackupInformation `
  -ResourceGroupName "rg" `
  -AccountName "mongodbpitracc" `
  -DatabaseName "db1" `
  -Name "col1" `
  -Location "eastus"

샘플 응답(UTC 형식):

LatestRestorableTimestamp
-------------------------
10/26/2021 6:27:22 PM

CLI

az cosmosdb mongodb retrieve-latest-backup-time \
  -g {resourcegroup} \
  -a {accountname} \
  -d {db_name} \
  -c {collection_name} \
  -l {location}

샘플 요청:

az cosmosdb mongodb retrieve-latest-backup-time \
  -g "rg" \
  -a "mongodbpitracc" \
  -d "db1" \
  -c "col1" \
  -l "eastus"

샘플 응답:

{
  "continuousBackupInformation": {
    "latestRestorableTimestamp": "10/26/2021 5:27:45 PM"
  }
}

MongoDB 데이터베이스

다음 스크립트를 사용하여 데이터베이스에 대해 복원 가능한 최신 타임스탬프를 가져옵니다. 이 스크립트는 이 데이터베이스 내의 모든 컬렉션을 다시 실행하고 모든 컬렉션의 복원 가능한 최신 최소 타임스탬프를 반환합니다.

Function Get-LatestRestorableTimestampForMongoDBDatabase {
[CmdletBinding()]
param(
    [Parameter(Position = 0, mandatory = $true)]
    [string] $resourceGroupName,
    [Parameter(Position = 1, mandatory = $true)]
    [string] $accountName,
    [Parameter(Position = 2, mandatory = $true)]
    [string] $databaseName,
    [Parameter(Position = 3, mandatory = $true)]
    [string] $location)
    
Write-Host
Write-Host "Latest restorable timestamp for a database is minimum of restorable timestamps of all the underlying collections"
Write-Host

Write-Debug "Listing all collections in database: $databaseName"
$collections = Get-AzCosmosDBMongoDBCollection -ResourceGroupName $resourceGroupName -AccountName $accountName -DatabaseName $databaseName

If (-Not $collections) {
    throw "Error: Found no collections to restore in the given database."
}

Write-Debug "Found $($collections.Length) collections under database $databaseName"

$latestRestorableTimestampForDatabase = [DateTime]::MaxValue
foreach ($collection in $collections) {
    Write-Debug "Getting latest restorable timestamp for collection: $($collection.Name)"

    $latestRestorableTimestampForCollection = Get-AzCosmosDBMongoDBCollectionBackupInformation -ResourceGroupName $resourceGroupName -AccountName $accountName -DatabaseName $databaseName -Name $collection.Name -Location $location

    Write-Debug "Latest Restorable Timestamp for collection $($collection.Name): $($latestRestorableTimestampForCollection.LatestRestorableTimestamp)"

    $latestRestorableTimestampForCollectionDateTime = [DateTime]$latestRestorableTimestampForCollection.LatestRestorableTimestamp

    If ($latestRestorableTimestampForCollectionDateTime -lt $latestRestorableTimestampForDatabase) {
        Write-Debug "Latest Restorable Timestamp for collection $($collection.Name) is less than current database restorable timestamp: $latestRestorableTimestampForDatabase"

        $latestRestorableTimestampForDatabase = $latestRestorableTimestampForCollectionDateTime
    }

    Write-Debug "Latest Restorable Timestamp for database so far: $latestRestorableTimestampForDatabase"
}

if ($latestRestorableTimestampForDatabase -eq [DateTime]::MaxValue) {
    throw "Error: Failed to retrieve latest backup timestamp for database: $databaseName"
}

Write-Debug "Latest Restorable Timestamp in UTC for database $($databaseName): $latestRestorableTimestampForDatabase"

return $latestRestorableTimestampForDatabase
}

구문:

Get-LatestRestorableTimestampForMongoDBDatabase `
  -ResourceGroupName <resourceGroup> `
  -AccountName <account> `
  -DatabaseName <database> `
  -Location <location>

샘플 요청:

Import-Module .\LatestRestorableTimestampForMongoDBDatabase.ps1
Get-LatestRestorableTimestampForMongoDBDatabase -ResourceGroupName rg -accountName mongopitracc -databaseName db1 -location eastus

샘플 응답(UTC 형식):

Latest restorable timestamp for a database is minimum of restorable timestamps of all the underlying collections
Wednesday, November 3, 2021 8:31:27 PM

MongoDB 계정

다음 스크립트를 사용하여 MongoDB 계정에 대해 복원 가능한 최신 타임스탬프를 가져올 수 있습니다. 이 스크립트는 이 계정 내의 모든 컨테이너를 다시 실행하고 모든 컬렉션의 복원 가능한 최신 최소 타임스탬프를 반환합니다.

Function Get-LatestRestorableTimestampForMongoDBAccount {
[CmdletBinding()]
param(
    [Parameter(Position = 0, mandatory = $true)]
    [string] $resourceGroupName,
    [Parameter(Position = 1, mandatory = $true)]
    [string] $accountName,
    [Parameter(Position = 2, mandatory = $true)]
    [string] $location)

Write-Host
Write-Host "Latest restorable timestamp for an account is minimum of restorable timestamps of all the underlying collections"
Write-Host

Write-Debug "Listing all databases in account: $accountName"

$databases = Get-AzCosmosDBMongoDBDatabase -ResourceGroupName $resourceGroupName -AccountName $accountName
Write-Debug "Found $($databases.Length) databases under account $accountName"

$latestRestorableTimestampForAccount = [DateTime]::MaxValue

foreach ($database in $databases) {
    Write-Debug "Listing all collections in database: $($database.Name)"
    $collections = Get-AzCosmosDBMongoDBCollection -ResourceGroupName $resourceGroupName -AccountName $accountName -DatabaseName $($database.Name)

    If (-Not $collections) {
        throw "Error: Found no collections to restore in the given database."
    }

    Write-Debug "Found $($collections.Length) collections under database $($database.Name)"

    foreach ($collection in $collections) {
        Write-Debug "Getting latest restorable timestamp for collection: $($collection.Name)"

        $latestRestorableTimestampForCollection = Get-AzCosmosDBMongoDBCollectionBackupInformation -ResourceGroupName $resourceGroupName -AccountName $accountName -DatabaseName $database.Name -Name $collection.Name -Location $location

        Write-Debug "Latest Restorable Timestamp for collection $($collection.Name): $($latestRestorableTimestampForCollection.LatestRestorableTimestamp)"

        $latestRestorableTimestampForCollectionDateTime = [DateTime]$latestRestorableTimestampForCollection.LatestRestorableTimestamp

        If ($latestRestorableTimestampForCollectionDateTime -lt $latestRestorableTimestampForAccount) {
            Write-Debug "Latest Restorable Timestamp for collection $($collection.Name) is less than current database restorable timestamp: $latestRestorableTimestampForAccount"

            $latestRestorableTimestampForAccount = $latestRestorableTimestampForCollectionDateTime
        }

        Write-Debug "Latest Restorable Timestamp for database so far: $latestRestorableTimestampForAccount"
    }
}

if ($latestRestorableTimestampForAccount -eq [DateTime]::MaxValue) {
    throw "Error: Failed to retrieve latest backup timestamp for account: $accountName"
}

Write-Debug "Latest Restorable Timestamp in UTC for account $($accountName): $latestRestorableTimestampForAccount"

return $latestRestorableTimestampForAccount
}

구문:

Get-LatestRestorableTimestampForMongoDBAccount `
  -ResourceGroupName <resourceGroupName> `
  -AccountName <accountName> `
  -Location <location>

샘플 요청:

Import-Module .\LatestRestorableTimestampForMongoDBAccount.ps1
Get-LatestRestorableTimestampForMongoDBAccount `
  -ResourceGroupName rg `
  -AccountName mongopitracc `
  -Location eastus

샘플 응답(UTC 형식):

Latest restorable timestamp for an account is minimum of restorable timestamps of all the underlying collections
Wednesday, November 3, 2021 8:33:49 PM

Gremlin Graph 백업 정보

PowerShell

Get-AzCosmosDBGremlinGraphBackupInformation  `
  -AccountName <System.String> `
  -GremlinDatabaseName  <System.String> `
  [-DefaultProfile <Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer>] `
  -Location <System.String> `
  -Name <System.String> `
  -ResourceGroupName <System.String> [<CommonParameters>]

샘플 요청:

Get-AzCosmosDBGremlinGraphBackupInformation  `
  -ResourceGroupName "rg" `
  -AccountName "amisigremlinpitracc1" `
  -GremlinDatabaseName  "db1" `
  -Name "graph1" `
  -Location "eastus"

샘플 응답(UTC 형식):

LatestRestorableTimestamp
-------------------------
3/1/2022 2:19:14 AM 

CLI

az cosmosdb gremlin retrieve-latest-backup-time \
  -g {resourcegroup} \
  -a {accountname} \
  -d {db_name} \
  -c {graph_name} \
  -l {location}

샘플 요청:

az cosmosdb gremlin retrieve-latest-backup-time \
  -g "rg" \
  -a "amisigremlinpitracc1" \
  -d "db1" \
  -c "graph1" \
  -l "eastus"

샘플 응답:

{
  "continuousBackupInformation": {
    "latestRestorableTimestamp": "3/2/2022 5:31:13 AM"
  }
}

테이블 백업 정보

PowerShell

Get-AzCosmosDBTableBackupInformation   `
  -AccountName <System.String> `
  [-DefaultProfile <Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer>] `
  -Location <System.String> `
  -Name <System.String> `
  -ResourceGroupName <System.String> [<CommonParameters>]

샘플 요청:

Get-AzCosmosDBTableBackupInformation   `
  -ResourceGroupName "rg" `
  -AccountName "amisitablepitracc1" `
  -Name "table1" `
  -Location "eastus"

샘플 응답(UTC 형식):

LatestRestorableTimestamp
-------------------------
3/2/2022 2:19:15 AM 

CLI

az cosmosdb table retrieve-latest-backup-time \
  -g {resourcegroup} \
  -a {accountname} \
  -c {table_name} \
  -l {location}

샘플 요청:

az cosmosdb table retrieve-latest-backup-time \
  -g "rg" \
  -a "amisitablepitracc1" \
  -c "table1" \
  -l "eastus"

샘플 응답:

{
  "continuousBackupInformation": {
    "latestRestorableTimestamp": "3/2/2022 5:33:47 AM"
  }
}

다음 단계