Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/CosmosDB/CosmosDB.Test/ScenarioTests/RestoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,19 @@ public void TestProvisionCosmosDBAccountBackupPolicyWithContinuous7DaysCmdLets()
{
TestRunner.RunTestScript("Test-ProvisionCosmosDBAccountBackupPolicyWithContinuous7DaysCmdLets");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestCrossRegionRestoreAccountCmdlets()
{
TestRunner.RunTestScript("Test-CrossRegionRestoreAccountCmdlets");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestCrossRegionRestoreSingleRegionAccountCmdlets()
{
TestRunner.RunTestScript("Test-CrossRegionRestoreSingleRegionAccountCmdlets");
}
}
}
101 changes: 101 additions & 0 deletions src/CosmosDB/CosmosDB.Test/ScenarioTests/RestoreTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -784,4 +784,105 @@ function Test-ProvisionCosmosDBAccountBackupPolicyWithContinuous7DaysCmdLets {
Assert-NotNull $sourceRestorableAccount.DatabaseAccountName
Assert-NotNull $sourceRestorableAccount.CreationTime
Assert-NotNull $sourceRestorableAccount.OldestRestorableTime
}

function Test-CrossRegionRestoreAccountCmdlets {
#use an existing account with the following information
$rgName = "PSCosmosDBResourceGroup53"
$cosmosDBAccountName = "ps-xrr-cosmosdb-12105-restored"
$sourceCosmosDBAccountName = "ps-xrr-cosmosdb-12105"
$databaseName = "TestDB1";
$collectionName1 = "TestCollectionInDB1";
$collectionName2 = "TestCollectionInDB2";
$location = "West Central US"
$apiKind = "Sql"
$consistencyLevel = "Session"
$PartitionKeyPathValue = "/foo/bar"
$PartitionKeyKindValue = "Hash"
$locations = @()
$locations += New-AzCosmosDBLocationObject -Location "West Central US" -FailoverPriority 0 -IsZoneRedundant 0
$locations += New-AzCosmosDBLocationObject -Location "North Central US" -FailoverPriority 1 -IsZoneRedundant 0
$targetLocation = "North Central US"
$sourceBackupLocation = "West Central US"

$resourceGroup = New-AzResourceGroup -ResourceGroupName $rgName -Location $location
New-AzCosmosDBAccount -ResourceGroupName $rgName -LocationObject $locations -Name $sourceCosmosDBAccountName -ApiKind $apiKind -DefaultConsistencyLevel $consistencyLevel -BackupPolicyType Continuous
$NewDatabase = New-AzCosmosDBSqlDatabase -AccountName $sourceCosmosDBAccountName -ResourceGroupName $rgName -Name $databaseName
$NewContainer = New-AzCosmosDBSqlContainer -AccountName $sourceCosmosDBAccountName -ResourceGroupName $rgName -DatabaseName $databaseName -Name $collectionName1 -PartitionKeyPath $PartitionKeyPathValue -PartitionKeyKind $PartitionKeyKindValue -Throughput 600
$NewContainer = New-AzCosmosDBSqlContainer -AccountName $sourceCosmosDBAccountName -ResourceGroupName $rgName -DatabaseName $databaseName -Name $collectionName2 -PartitionKeyPath $PartitionKeyPathValue -PartitionKeyKind $PartitionKeyKindValue -Throughput 600

$datatabaseToRestore = New-AzCosmosDBDatabaseToRestore -DatabaseName $databaseName -CollectionName $collectionName1, $collectionName2
$sourceCosmosDBAccount = Get-AzCosmosDBAccount -Name $sourceCosmosDBAccountName -ResourceGroupName $rgName
Assert-NotNull $sourceCosmosDBAccount.Location
Assert-AreEqual $sourceCosmosDBAccount.Location $location

$sourceRestorableAccount = Get-AzCosmosDBRestorableDatabaseAccount -Location $sourceCosmosDBAccount.Location -DatabaseAccountInstanceId $sourceCosmosDBAccount.InstanceId

Start-Sleep -s 3662
$restoreTimestampInUtc = $sourceRestorableAccount.CreationTime.AddSeconds(3610)

$restoredCosmosDBAccount = Restore-AzCosmosDBAccount -RestoreTimestampInUtc $restoreTimestampInUtc -SourceDatabaseAccountName $sourceCosmosDBAccountName -SourceBackupLocation $sourceBackupLocation -Location $targetLocation -TargetResourceGroupName $rgName -TargetDatabaseAccountName $cosmosDBAccountName -DatabasesToRestore $datatabaseToRestore

Assert-NotNull $sourceRestorableAccount
Assert-AreEqual $restoredCosmosDBAccount.Name $cosmosDBAccountName
Assert-AreEqual $restoredCosmosDBAccount.CreateMode "Restore"
Assert-NotNull $restoredCosmosDBAccount.RestoreParameters
Assert-AreEqual $restoredCosmosDBAccount.RestoreParameters.RestoreSource $sourceRestorableAccount.Id

#Assert-AreEqual $restoredCosmosDBAccount.RestoreParameters.RestoreTimestampInUtc.ToUniversalTime() $inputRestoreTS.ToUniversalTime()
Assert-NotNull $restoredCosmosDBAccount.RestoreParameters.DatabasesToRestore
Assert-AreEqual $restoredCosmosDBAccount.RestoreParameters.DatabasesToRestore[0].DatabaseName $databaseName
Assert-AreEqual $restoredCosmosDBAccount.RestoreParameters.DatabasesToRestore[0].CollectionNames[0] $collectionName1
Assert-AreEqual $restoredCosmosDBAccount.RestoreParameters.SourceBackupLocation $sourceBackupLocation
Assert-AreEqual $restoredCosmosDBAccount.WriteLocations[0].LocationName $targetLocation
}

function Test-CrossRegionRestoreSingleRegionAccountCmdlets {
#use an existing account with the following information
$rgName = "PSCosmosDBResourceGroup54"
$cosmosDBAccountName = "ps-xrr-cosmosdb-12106-restored"
$sourceCosmosDBAccountName = "ps-xrr-cosmosdb-12106"
$databaseName = "TestDB1";
$collectionName1 = "TestCollectionInDB1";
$collectionName2 = "TestCollectionInDB2";
$location = "West Central US"
$apiKind = "Sql"
$consistencyLevel = "Session"
$PartitionKeyPathValue = "/foo/bar"
$PartitionKeyKindValue = "Hash"
$locations = @()
$locations += New-AzCosmosDBLocationObject -Location "West Central US" -FailoverPriority 0 -IsZoneRedundant 0
$targetLocation = "North Central US"
$sourceBackupLocation = "West Central US"

$resourceGroup = New-AzResourceGroup -ResourceGroupName $rgName -Location $location
New-AzCosmosDBAccount -ResourceGroupName $rgName -LocationObject $locations -Name $sourceCosmosDBAccountName -ApiKind $apiKind -DefaultConsistencyLevel $consistencyLevel -BackupPolicyType Continuous
$NewDatabase = New-AzCosmosDBSqlDatabase -AccountName $sourceCosmosDBAccountName -ResourceGroupName $rgName -Name $databaseName
$NewContainer = New-AzCosmosDBSqlContainer -AccountName $sourceCosmosDBAccountName -ResourceGroupName $rgName -DatabaseName $databaseName -Name $collectionName1 -PartitionKeyPath $PartitionKeyPathValue -PartitionKeyKind $PartitionKeyKindValue -Throughput 600
$NewContainer = New-AzCosmosDBSqlContainer -AccountName $sourceCosmosDBAccountName -ResourceGroupName $rgName -DatabaseName $databaseName -Name $collectionName2 -PartitionKeyPath $PartitionKeyPathValue -PartitionKeyKind $PartitionKeyKindValue -Throughput 600

$datatabaseToRestore = New-AzCosmosDBDatabaseToRestore -DatabaseName $databaseName -CollectionName $collectionName1, $collectionName2
$sourceCosmosDBAccount = Get-AzCosmosDBAccount -Name $sourceCosmosDBAccountName -ResourceGroupName $rgName
Assert-NotNull $sourceCosmosDBAccount.Location
Assert-AreEqual $sourceCosmosDBAccount.Location $location

$sourceRestorableAccount = Get-AzCosmosDBRestorableDatabaseAccount -Location $sourceCosmosDBAccount.Location -DatabaseAccountInstanceId $sourceCosmosDBAccount.InstanceId

Start-Sleep -s 3662
$restoreTimestampInUtc = $sourceRestorableAccount.CreationTime.AddSeconds(3610)

$restoredCosmosDBAccount = Restore-AzCosmosDBAccount -RestoreTimestampInUtc $restoreTimestampInUtc -SourceDatabaseAccountName $sourceCosmosDBAccountName -SourceBackupLocation $sourceBackupLocation -Location $targetLocation -TargetResourceGroupName $rgName -TargetDatabaseAccountName $cosmosDBAccountName -DatabasesToRestore $datatabaseToRestore

Assert-NotNull $sourceRestorableAccount
Assert-AreEqual $restoredCosmosDBAccount.Name $cosmosDBAccountName
Assert-AreEqual $restoredCosmosDBAccount.CreateMode "Restore"
Assert-NotNull $restoredCosmosDBAccount.RestoreParameters
Assert-AreEqual $restoredCosmosDBAccount.RestoreParameters.RestoreSource $sourceRestorableAccount.Id

#Assert-AreEqual $restoredCosmosDBAccount.RestoreParameters.RestoreTimestampInUtc.ToUniversalTime() $inputRestoreTS.ToUniversalTime()
Assert-NotNull $restoredCosmosDBAccount.RestoreParameters.DatabasesToRestore
Assert-AreEqual $restoredCosmosDBAccount.RestoreParameters.DatabasesToRestore[0].DatabaseName $databaseName
Assert-AreEqual $restoredCosmosDBAccount.RestoreParameters.DatabasesToRestore[0].CollectionNames[0] $collectionName1
Assert-AreEqual $restoredCosmosDBAccount.RestoreParameters.SourceBackupLocation $sourceBackupLocation
Assert-AreEqual $restoredCosmosDBAccount.WriteLocations[0].LocationName $targetLocation
}
Loading