Skip to content

PS cosmos db restore command: Skipping client side restore validation check #28171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 24, 2025
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.

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 1.18.1
* Fixed incorrect help documents for MongoDB cmdlets.
Expand Down
92 changes: 0 additions & 92 deletions src/CosmosDB/CosmosDB/CosmosDBAccount/RestoreAzCosmosDBAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public override void ExecuteCmdlet()
return;
}

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

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

// Validate if source account is empty if the source account is a live account.
if (!isSourceRestorableAccountDeleted)
{
bool restorableResourcesNotFound = false;
if (sourceAccountToRestore.ApiType.Equals("Sql", StringComparison.OrdinalIgnoreCase))
{
try
{
IEnumerable<RestorableSqlResourcesGetResult> restorableResources = CosmosDBManagementClient.RestorableSqlResources.ListWithHttpMessagesAsync(
sourceAccountToRestore.Location,
sourceAccountToRestore.Name,
Location,
utcRestoreDateTime.ToString()).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 {Location}");
return;
}
}
else if (sourceAccountToRestore.ApiType.Equals("MongoDB", StringComparison.OrdinalIgnoreCase))
{
try
{
IEnumerable<RestorableMongodbResourcesGetResult> restorableResources = CosmosDBManagementClient.RestorableMongodbResources.ListWithHttpMessagesAsync(
sourceAccountToRestore.Location,
sourceAccountToRestore.Name,
Location,
utcRestoreDateTime.ToString()).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 {Location}");
return;
}
}
else if (sourceAccountToRestore.ApiType.Equals("Gremlin, Sql", StringComparison.OrdinalIgnoreCase))
{
try
{
IEnumerable<RestorableGremlinResourcesGetResult> restorableResources = CosmosDBManagementClient.RestorableGremlinResources.ListWithHttpMessagesAsync(
sourceAccountToRestore.Location,
sourceAccountToRestore.Name,
Location,
utcRestoreDateTime.ToString()).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 {Location}");
return;
}
}
else if (sourceAccountToRestore.ApiType.Equals("Table, Sql", StringComparison.OrdinalIgnoreCase))
{
try
{
IEnumerable<RestorableTableResourcesGetResult> restorableResources = CosmosDBManagementClient.RestorableTableResources.ListWithHttpMessagesAsync(
sourceAccountToRestore.Location,
sourceAccountToRestore.Name,
Location,
utcRestoreDateTime.ToString()).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 {Location}");
return;
}
}
else
{
WriteWarning($"Provided API Type {sourceAccountToRestore.ApiType} is not supported");
return;
}

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

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