Skip to content

Fixing restore and recovery bugs https://microsoft.visualstudio.com/w… #344

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 2 commits into from
Aug 10, 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,
Copy link

Choose a reason for hiding this comment

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

See if we can put common part of conversion between List and Get into another function

Copy link
Author

Choose a reason for hiding this comment

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

there are few additional field in detail thats why we kept it separate. I will check the possibility and do it in next checkin

BackupManagementType = item.BackupManagementType,
ItemName = protectedItemName,
ContainerName = containerUri,
ContainerName = containerName,
ContainerType = item.ContainerType,
RecoveryPointTime = recPointTime,
RecoveryPointType = recPoint.RecoveryPointType,
Expand All @@ -74,20 +77,7 @@ public static List<RecoveryPointBase> GetPSAzureRecoveryPoints(
recPoint.IsSourceVMEncrypted.Value : false,
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 All @@ -106,7 +96,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 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 @@ -312,7 +312,6 @@ public CmdletModel.RecoveryPointBase GetRecoveryPointDetails()
queryFilter.StartDate = CommonHelpers.GetDateTimeStringForService(startDate);
queryFilter.EndDate = CommonHelpers.GetDateTimeStringForService(endDate);
RecoveryPointListResponse rpListResponse = null;

rpListResponse = ServiceClientAdapter.GetRecoveryPoints(containerUri, protectedItemName, queryFilter);
return RecoveryPointConversions.GetPSAzureRecoveryPoints(rpListResponse, item);
}
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;
Copy link

Choose a reason for hiding this comment

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

Move up System usings

Copy link
Author

Choose a reason for hiding this comment

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

Its sorted by VS in alphabetical order. Not changing it.

using System.Collections.Generic;
using System.IO;

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS
Expand All @@ -35,16 +37,19 @@ 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 +68,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 +78,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 Down