Skip to content
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

[RecoveryServices.Backup] VM restore fix for #7823 #7925

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
CreateNewCloudService = false,
RecoveryPointId = rp.RecoveryPointId,
RecoveryType = RecoveryType.RestoreDisks,
Region = vaultLocation,
Region = vaultLocation ?? ServiceClientAdapter.BmsAdapter.GetResourceLocation(),
StorageAccountId = storageAccountResource.Id,
SourceResourceId = rp.SourceResourceId,
TargetResourceGroupId = targetResourceGroupName != null ?
Expand All @@ -315,7 +315,7 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
triggerRestoreRequest,
vaultName: vaultName,
resourceGroupName: resourceGroupName,
vaultLocation: vaultLocation);
vaultLocation: vaultLocation ?? ServiceClientAdapter.BmsAdapter.GetResourceLocation());
return response;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public RestAzureNS.AzureOperationResponse RestoreDisk(
string resourceGroupName = null,
string vaultLocation = null)
{
vaultLocation = vaultLocation ?? BmsAdapter.GetResourceLocation();
Dictionary<UriEnums, string> uriDict = HelperUtils.ParseUri(rp.Id);
string containerUri = HelperUtils.GetContainerUri(uriDict, rp.Id);
string protectedItemUri = HelperUtils.GetProtectedItemUri(uriDict, rp.Id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public partial class ServiceClientAdapter
const string AzureFabricName = "Azure";
public const string ResourceProviderProductionNamespace = "Microsoft.RecoveryServices";

ClientProxy<RecoveryServicesBackupNS.RecoveryServicesBackupClient> BmsAdapter;
public ClientProxy<RecoveryServicesBackupNS.RecoveryServicesBackupClient> BmsAdapter;

ClientProxy<RecoveryServicesNS.RecoveryServicesClient> RSAdapter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,10 @@ function Test-AzureVMSetVaultContext
# Setup
$vm = Create-VM $resourceGroupName $location
$vault = Create-RecoveryServicesVault $resourceGroupName $location
$saName = Create-SA $resourceGroupName $location

# Sleep to give the service time to add the default policy to the vault
Start-TestSleep 5000
Start-TestSleep 5000

Set-AzureRmRecoveryServicesVaultContext -Vault $vault

Expand All @@ -384,6 +385,24 @@ function Test-AzureVMSetVaultContext
-Container $container `
-WorkloadType AzureVM

$backupJob = Backup-AzureRmRecoveryServicesBackupItem `
-Item $item | Wait-AzureRmRecoveryServicesBackupJob;

# Get Recovery Point
$backupStartTime = $backupJob.StartTime.AddMinutes(-1);
$backupEndTime = $backupJob.EndTime.AddMinutes(1);
$rps = Get-AzureRmRecoveryServicesBackupRecoveryPoint `
-Item $item `
-StartDate $backupStartTime `
-EndDate $backupEndTime

# Restore item
$restoreJob1 = Restore-AzureRmRecoveryServicesBackupItem `
-RecoveryPoint $rps[0] `
-StorageAccountName $saName `
-StorageAccountResourceGroupName $resourceGroupName | `
Wait-AzureRmRecoveryServicesBackupJob

# Disable protection
Disable-AzureRmRecoveryServicesBackupProtection `
-Item $item `
Expand Down
772,725 changes: 756,187 additions & 16,538 deletions ...ands.RecoveryServices.Backup.Test.ScenarioTests.ItemTests/TestAzureVMSetVaultContext.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
## Current Release
* Added client side validations for Azure File Share restore operations.
* Made storageAccountName and storageAccountResourceGroupName optional for afs restore.
* Fixed restore cmdlet while using Set-vaultContext.

## Version 4.5.1
* Fix for modifying policy for a protected file share.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public abstract class RSBackupVaultCmdletBase : RecoveryServicesBackupCmdletBase
/// ARM ID of the Recovery Services Vault.
/// </summary>
[Parameter(Mandatory = false, HelpMessage = "ARM ID of the Recovery Services Vault.",
ValueFromPipeline = true)]
ValueFromPipelineByPropertyName = true)]
Copy link
Member

Choose a reason for hiding this comment

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

@siddharth7 does this scenario currently break users? i.e., are users able to write scripts that use this parameter via piping without any exceptions?

Copy link
Member

Choose a reason for hiding this comment

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

@siddharth7 resolved offline -- users currently using this piping scenario are broken, so this is not a breaking change. The exception in the build can be suppressed.

[Alias("Id")]
[ValidateNotNullOrEmpty]
public string VaultId { get; set; }

Expand Down