Skip to content
Merged
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
10 changes: 5 additions & 5 deletions src/CosmosDB/CosmosDB.Test/ScenarioTests/RestoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public RestoreTests(Xunit.Abstractions.ITestOutputHelper output): base(output)
{
}

[Fact(Skip = "Output of DateTime.ToString() is different in MacOs.")]
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestSqlRestoreAccountCmdlets()
{
TestRunner.RunTestScript("Test-SqlRestoreAccountCmdlets");
}

[Fact(Skip = "Output of DateTime.ToString() is different in MacOs.")]
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestSqlRestoreAccountPublicNetworkAccessCmdlets()
{
Expand Down Expand Up @@ -65,21 +65,21 @@ public void TestRestoreFailuresAccountCmdlets()
TestRunner.RunTestScript("Test-RestoreFailuresAccountCmdlets");
}

[Fact(Skip = "Output of DateTime.ToString() is different in MacOs.")]
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGremlinRestoreAccountCmdlets()
{
TestRunner.RunTestScript("Test-GremlinRestoreAccountCmdlets");
}

[Fact(Skip = "Output of DateTime.ToString() is different in MacOs.")]
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGremlinRestoreFromNewAccountCmdlets()
{
TestRunner.RunTestScript("Test-GremlinRestoreFromNewAccountCmdlets");
}

[Fact(Skip = "Output of DateTime.ToString() is different in MacOs.")]
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestTableRestoreAccountCmdlets()
{
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/CosmosDB/CosmosDB/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
-->

## Upcoming Release
* Fixed issue where the restore command failed to detect the source account, even when it existed.

## Version 2.0.7
* Added support for throughput buckets.
Expand Down
98 changes: 0 additions & 98 deletions src/CosmosDB/CosmosDB/CosmosDBAccount/RestoreAzCosmosDBAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public override void ExecuteCmdlet()
return;
}

bool isSourceRestorableAccountDeleted = false;
List<RestorableDatabaseAccountGetResult> restorableDatabaseAccounts = CosmosDBManagementClient.RestorableDatabaseAccounts.ListWithHttpMessagesAsync().GetAwaiter().GetResult().Body.ToList();

RestorableDatabaseAccountGetResult sourceAccountToRestore = null;
Expand All @@ -109,14 +108,12 @@ public override void ExecuteCmdlet()
if (restorableAccount.DeletionTime >= utcRestoreDateTime)
{
sourceAccountToRestore = restorableAccount;
isSourceRestorableAccountDeleted = true;
break;
}
}
else
{
sourceAccountToRestore = restorableAccount;
isSourceRestorableAccountDeleted = false;
break;
}
}
Expand All @@ -129,101 +126,6 @@ public override void ExecuteCmdlet()
return;
}

// Validate if source account is empty if the source account is a live account.
if (!isSourceRestorableAccountDeleted)
{
string sourceLocation = Location;
if (!string.IsNullOrEmpty(SourceBackupLocation))
{
sourceLocation = SourceBackupLocation;
}

bool restorableResourcesNotFound = false;
if (sourceAccountToRestore.ApiType.Equals("Sql", StringComparison.OrdinalIgnoreCase))
{
try
{
IEnumerable<RestorableSqlResourcesGetResult> restorableResources = CosmosDBManagementClient.RestorableSqlResources.ListWithHttpMessagesAsync(
sourceAccountToRestore.Location,
sourceAccountToRestore.Name,
sourceLocation,
utcRestoreDateTime.ToString("u")).GetAwaiter().GetResult().Body;

restorableResourcesNotFound = restorableResources == null || !restorableResources.Any();
}
catch (Exception)
{
WriteWarning($"No database accounts found with matching account name {SourceDatabaseAccountName} that was alive at given utc-timestamp {utcRestoreDateTime} in location {sourceLocation}");
return;
}
}
else if (sourceAccountToRestore.ApiType.Equals("MongoDB", StringComparison.OrdinalIgnoreCase))
{
try
{
IEnumerable<RestorableMongodbResourcesGetResult> restorableResources = CosmosDBManagementClient.RestorableMongodbResources.ListWithHttpMessagesAsync(
sourceAccountToRestore.Location,
sourceAccountToRestore.Name,
sourceLocation,
utcRestoreDateTime.ToString("u")).GetAwaiter().GetResult().Body;

restorableResourcesNotFound = restorableResources == null || !restorableResources.Any();
}
catch (Exception)
{
WriteWarning($"No database accounts found with matching account name {SourceDatabaseAccountName} that was alive at given utc-timestamp {utcRestoreDateTime} in location {sourceLocation}");
return;
}
}
else if (sourceAccountToRestore.ApiType.Equals("Gremlin, Sql", StringComparison.OrdinalIgnoreCase))
{
try
{
IEnumerable<RestorableGremlinResourcesGetResult> restorableResources = CosmosDBManagementClient.RestorableGremlinResources.ListWithHttpMessagesAsync(
sourceAccountToRestore.Location,
sourceAccountToRestore.Name,
sourceLocation,
utcRestoreDateTime.ToString("u")).GetAwaiter().GetResult().Body;

restorableResourcesNotFound = restorableResources == null || !restorableResources.Any();
}
catch (Exception)
{
WriteWarning($"No database accounts found with matching account name {SourceDatabaseAccountName} that was alive at given utc-timestamp {utcRestoreDateTime} in location {sourceLocation}");
return;
}
}
else if (sourceAccountToRestore.ApiType.Equals("Table, Sql", StringComparison.OrdinalIgnoreCase))
{
try
{
IEnumerable<RestorableTableResourcesGetResult> restorableResources = CosmosDBManagementClient.RestorableTableResources.ListWithHttpMessagesAsync(
sourceAccountToRestore.Location,
sourceAccountToRestore.Name,
sourceLocation,
utcRestoreDateTime.ToString("u")).GetAwaiter().GetResult().Body;

restorableResourcesNotFound = restorableResources == null || !restorableResources.Any();
}
catch (Exception)
{
WriteWarning($"No database accounts found with matching account name {SourceDatabaseAccountName} that was alive at given utc-timestamp {utcRestoreDateTime} in location {sourceLocation}");
return;
}
}
else
{
WriteWarning($"Provided API Type {sourceAccountToRestore.ApiType} is not supported");
return;
}

if (restorableResourcesNotFound)
{
WriteWarning($"Database account {SourceDatabaseAccountName} contains no restorable resources in location {sourceLocation} at given restore timestamp {utcRestoreDateTime} in location {sourceLocation}");
return;
}
}

// Trigger restore
PSRestoreParameters restoreParameters = new PSRestoreParameters()
{
Expand Down