Skip to content

Fixing restore and recovery bug #2823

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 1 commit into from
Aug 30, 2016
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ public static List<RecoveryPointBase> GetPSAzureRecoveryPoints(

Dictionary<UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
string containerUri = HelperUtils.GetContainerUri(uriDict, item.Id);
string protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, item.Id);
string protectedItemUri = HelperUtils.GetProtectedItemUri(uriDict, item.Id);

string containerName = IdUtils.GetNameFromUri(containerUri);
string protectedItemName = IdUtils.GetNameFromUri(protectedItemUri);

List<RecoveryPointBase> result = new List<RecoveryPointBase>();
foreach (ServiceClientModel.RecoveryPointResource rp in rpList.RecoveryPointList.RecoveryPoints)
Expand All @@ -61,7 +64,7 @@ public static List<RecoveryPointBase> GetPSAzureRecoveryPoints(
RecoveryPointId = rp.Name,
BackupManagementType = item.BackupManagementType,
ItemName = protectedItemName,
ContainerName = containerUri,
ContainerName = containerName,
ContainerType = item.ContainerType,
RecoveryPointTime = recPointTime,
RecoveryPointType = recPoint.RecoveryPointType,
Expand All @@ -75,19 +78,6 @@ public static List<RecoveryPointBase> GetPSAzureRecoveryPoints(
IlrSessionActive = recPoint.IsInstantILRSessionActive,
};

if (rpBase.EncryptionEnabled)
{
rpBase.KeyAndSecretDetails = new KeyAndSecretDetails()
{
SecretUrl = recPoint.KeyAndSecret.BekDetails.SecretUrl,
KeyUrl = recPoint.KeyAndSecret.KekDetails.KeyUrl,
SecretData = recPoint.KeyAndSecret.BekDetails.SecretData,
KeyBackupData = recPoint.KeyAndSecret.KekDetails.KeyBackupData,
KeyVaultId = recPoint.KeyAndSecret.KekDetails.KeyVaultId,
SecretVaultId = recPoint.KeyAndSecret.BekDetails.SecretVaultId,
};
}

result.Add(rpBase);
}

Expand Down Expand Up @@ -169,9 +159,11 @@ public static RecoveryPointBase GetPSAzureRecoveryPoints(
EncryptionEnabled = recPoint.IsSourceVMEncrypted.HasValue ?
recPoint.IsSourceVMEncrypted.Value : false,
IlrSessionActive = recPoint.IsInstantILRSessionActive,
SourceResourceId = item.SourceResourceId,
SourceVMStorageType = recPoint.SourceVMStorageType,
};

if (vmResult.EncryptionEnabled)
if (vmResult.EncryptionEnabled && recPoint.KeyAndSecret != null)
{
vmResult.KeyAndSecretDetails = new KeyAndSecretDetails()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,19 @@ public CmdletModel.RecoveryPointBase GetRecoveryPointDetails()
var rpResponse = ServiceClientAdapter.GetRecoveryPointDetails(
containerUri, protectedItemName, recoveryPointId);

var rp = RecoveryPointConversions.GetPSAzureRecoveryPoints(rpResponse, item);
var rp = RecoveryPointConversions.GetPSAzureRecoveryPoints(rpResponse, item) as AzureVmRecoveryPoint;

string keyFileDownloadLocation =
(string)ProviderData[RecoveryPointParams.KeyFileDownloadLocation];
string keyFileContent = ((AzureVmRecoveryPoint)rp).KeyAndSecretDetails.KeyBackupData;
if (!string.IsNullOrEmpty(keyFileDownloadLocation))
if (rp.EncryptionEnabled)
{
string absoluteFilePath = Path.Combine(keyFileDownloadLocation, "key.blob");
File.WriteAllBytes(absoluteFilePath, Convert.FromBase64String(keyFileContent));
}

string keyFileDownloadLocation =
(string)ProviderData[RecoveryPointParams.KeyFileDownloadLocation];
string keyFileContent = rp.KeyAndSecretDetails.KeyBackupData;
if (!string.IsNullOrEmpty(keyFileDownloadLocation))
{
string absoluteFilePath = Path.Combine(keyFileDownloadLocation, "key.blob");
File.WriteAllBytes(absoluteFilePath, Convert.FromBase64String(keyFileContent));
}
}
return rp;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
using System;
using System.Collections.Generic;
using System.IO;

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS
Expand All @@ -35,16 +37,18 @@ public BaseRecoveryServicesJobResponse RestoreDisk(AzureVmRecoveryPoint rp, stri
{
string resourceGroupName = BmsAdapter.GetResourceGroupName();
string resourceName = BmsAdapter.GetResourceName();
string vaultLocation = BmsAdapter.GetResourceLocation();
string containerName = rp.ContainerName;
string protectedItemName = rp.ItemName;
string 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);
string recoveryPointId = rp.RecoveryPointId;
//validtion block
if(storageAccountLocation != vaultLocation)
{
throw new Exception(Resources.RestoreDiskIncorrectRegion);
}
string vmType = containerName.Split(';')[1].Equals("iaasvmcontainer", StringComparison.OrdinalIgnoreCase)

string vmType = containerUri.Split(';')[1].Equals("iaasvmcontainer", StringComparison.OrdinalIgnoreCase)
? "Classic" : "Compute";
string strType = storageAccountType.Equals("Microsoft.ClassicStorage/StorageAccounts",
StringComparison.OrdinalIgnoreCase) ? "Classic" : "Compute";
Expand All @@ -63,18 +67,6 @@ public BaseRecoveryServicesJobResponse RestoreDisk(AzureVmRecoveryPoint rp, stri
SourceResourceId = rp.SourceResourceId,
};

if (rp.EncryptionEnabled)
{
restoreRequest.EncryptionDetails = new EncryptionDetails()
{
EncryptionEnabled = rp.EncryptionEnabled,
KekUrl = rp.KeyAndSecretDetails.KeyUrl,
KekVaultId = rp.KeyAndSecretDetails.KeyVaultId,
SecretKeyUrl = rp.KeyAndSecretDetails.SecretUrl,
SecretKeyVaultId = rp.KeyAndSecretDetails.SecretVaultId,
};
}

TriggerRestoreRequest triggerRestoreRequest = new TriggerRestoreRequest();
triggerRestoreRequest.Item = new RestoreRequestResource();
triggerRestoreRequest.Item.Properties = new RestoreRequest();
Expand All @@ -85,8 +77,8 @@ public BaseRecoveryServicesJobResponse RestoreDisk(AzureVmRecoveryPoint rp, stri
resourceName,
BmsAdapter.GetCustomRequestHeaders(),
AzureFabricName,
containerName,
protectedItemName,
containerUri,
protectedItemUri,
recoveryPointId,
triggerRestoreRequest,
BmsAdapter.CmdletCancellationToken).Result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
<Project>{5ee72c53-1720-4309-b54b-5fb79703195f}</Project>
<Name>Commands.Common</Name>
</ProjectReference>
<ProjectReference Include="..\Commands.RecoveryServices.Backup.Helpers\Commands.RecoveryServices.Backup.Helpers.csproj">
<Project>{0e1d3f36-e6c8-4764-8c7d-6f9ee537490c}</Project>
<Name>Commands.RecoveryServices.Backup.Helpers</Name>
</ProjectReference>
<ProjectReference Include="..\Commands.RecoveryServices.Backup.Models\Commands.RecoveryServices.Backup.Models.csproj">
<Project>{30b92759-50b3-494e-b9f0-ec9a2ce9d57b}</Project>
<Name>Commands.RecoveryServices.Backup.Models</Name>
Expand All @@ -104,4 +108,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function Test-GetAzureVMRecoveryPointsScenario
{
# 1. Create / update and get vault
$vaultLocation = get_available_location;
$vault = New-AzureRmRecoveryServicesVault `
$vault = New-AzureRmRecoveryServicesVault `
-Name $resourceName -ResourceGroupName $resourceGroupName -Location $vaultLocation;

# 2. Set vault context
Expand Down Expand Up @@ -236,9 +236,17 @@ function Test-GetAzureVMRecoveryPointsScenario
$backupEndTime = $backupJob.EndTime.AddMinutes(1);
$recoveryPoint = Get-AzureRmRecoveryServicesBackupRecoveryPoint `
-StartDate $backupStartTime -EndDate $backupEndTime -Item $item;

Assert-NotNull $recoveryPoint;
Assert-True { $recoveryPoint.ContainerName -match $vmUniqueName };

#Action get Recovery point detail
$recoveryPointDetail = Get-AzureRmRecoveryServicesBackupRecoveryPoint `
-RecoveryPointId $recoveryPoint[0].RecoveryPointId -Item $item;

Assert-NotNull $recoveryPointDetail;


}

function Test-RestoreAzureVMRItemScenario
Expand Down
Loading