Skip to content

[Az.RecoveryServices.Backup] Fix AFS Restore Command Bug #28302

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

IannGeorges
Copy link
Member

@IannGeorges IannGeorges commented Jul 30, 2025

Description

Implementing fix to handle cases where the source storage account is deleted & required sourceResourceId property is missing for restore request payload.

Tested restore where AFS source storage account was deleted before changes were made to reproduce bug.
Tested restore where AFS source storage account was deleted after changes were made to validate fix.

Mandatory Checklist

  • SHOULD update ChangeLog.md file(s) appropriately
    • Update src/{{SERVICE}}/{{SERVICE}}/ChangeLog.md.
      • A snippet outlining the change(s) made in the PR should be written under the ## Upcoming Release header in the past tense.
    • Should not change ChangeLog.md if no new release is required, such as fixing test case only.
  • SHOULD regenerate markdown help files if there is cmdlet API change. Instruction
  • SHOULD have proper test coverage for changes in pull request.
  • SHOULD NOT adjust version of module manually in pull request

@Copilot Copilot AI review requested due to automatic review settings July 30, 2025 06:17
Copy link

Thanks for your contribution! The pull request validation has started. Please revisit this comment for updated status.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Fixes a bug in the Azure File Share restore functionality where the restore command fails when the source storage account has been deleted, by implementing fallback logic to retrieve the sourceResourceId from the protected item when the primary method fails.

  • Adds exception handling around storage account resource retrieval with fallback to protected item
  • Implements validation to ensure sourceResourceId is available before proceeding with restore
  • Updates changelog to document the fix

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
ChangeLog.md Documents the bug fix for Azure File Share restore command
AzureFilesPsBackupProvider.cs Implements fallback logic to handle deleted source storage accounts during restore operations

// Validate that we have a source resource ID
if (storageAccountResource == null || string.IsNullOrEmpty(storageAccountResource.Id))
{
throw new ArgumentException(string.Format(Resources.AzureFileShareNotFound,
Copy link
Preview

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message uses 'AzureFileShareNotFound' resource which may not accurately describe the actual problem - missing source resource ID rather than a missing file share. Consider using a more specific error message that indicates the source storage account resource ID could not be retrieved.

Copilot uses AI. Check for mistakes.

// Create a minimal resource object with the source resource ID
if (!string.IsNullOrEmpty(sourceResourceId))
{
storageAccountResource = new GenericResource
Copy link
Preview

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a new GenericResource with minimal properties could lead to issues if other parts of the code expect additional properties to be populated. Consider documenting this limitation or ensuring all required properties are set.

Copilot uses AI. Check for mistakes.

GenericResource storageAccountResource = ServiceClientAdapter.GetStorageAccountResource(recoveryPoint.ContainerName.Split(';')[2]);
GenericResource storageAccountResource = null;
string sourceResourceId = null;
string storageAccountLocation = vaultLocation; // Default to vault location
Copy link
Preview

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assumption that the storage account location should default to vault location may not always be correct. Consider adding a comment explaining why this is a reasonable fallback or implement logic to determine the actual storage account location.

Suggested change
string storageAccountLocation = vaultLocation; // Default to vault location
// Default to vault location as a fallback. This assumption is based on the expectation
// that in most cases, the storage account and the vault are in the same location.
// However, this may not always be true. If the storage account location cannot be retrieved,
// we log a warning and proceed with the fallback. Ensure that this fallback is safe for your scenario.
string storageAccountLocation = vaultLocation;

Copilot uses AI. Check for mistakes.

@YanaXu
Copy link
Contributor

YanaXu commented Jul 31, 2025

/azp run

Copy link
Contributor

Azure Pipelines successfully started running 3 pipeline(s).

throw new ArgumentException(string.Format(Resources.AzureFileShareNotFound,
recoveryPoint.ContainerName));
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a test case for this. also have we thoroughly tested this change?

{
storageAccountResource = new GenericResource
{
Id = sourceResourceId,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initiliazing this way might not work. please confirm

@NoriZC
Copy link
Contributor

NoriZC commented Aug 4, 2025

Hi @IannGeorges please also sync main branch in next commit to keep the changelog updated.

@NoriZC NoriZC self-assigned this Aug 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants