Skip to content

[Az.RecoveryServices.Backup] Archive preview release #14413

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
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 @@ -16,6 +16,7 @@
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
using System;
using System.Collections.Generic;
using System.Linq;
using ServiceClientModel = Microsoft.Azure.Management.RecoveryServices.Backup.Models;

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers
Expand All @@ -25,6 +26,101 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers
/// </summary>
public class RecoveryPointConversions
{

/// <summary>
/// filter RPs based on tier
/// </summary>
/// <param name="recoveryPointList"></param>
/// <param name="Tier"></param>
/// <returns></returns>
public static List<RecoveryPointBase> FilterRPsBasedOnTier(List<RecoveryPointBase> recoveryPointList, RecoveryPointTier Tier)
{
if (Tier != 0)
{
recoveryPointList = recoveryPointList.Where(
recoveryPoint =>
{
if (recoveryPoint.GetType() == typeof(AzureVmRecoveryPoint))
{
return ((AzureVmRecoveryPoint)recoveryPoint).RecoveryPointTier == Tier;
}

if (recoveryPoint.GetType() == typeof(AzureWorkloadRecoveryPoint))
{
return ((AzureWorkloadRecoveryPoint)recoveryPoint).RecoveryPointTier == Tier;
}

return false;
}).ToList();
}
return recoveryPointList;
}

/// <summary>
/// filter move readness based on target tier
/// </summary>
/// <param name="recoveryPointList"></param>
/// <param name="TargetTier"></param>
/// <param name="IsReadyForMove"></param>
/// <returns></returns>
public static List<RecoveryPointBase> CheckRPMoveReadiness(List<RecoveryPointBase> recoveryPointList, RecoveryPointTier targetTier, bool isReadyForMove)
{
if (recoveryPointList != null && targetTier != 0) // if TargetTier and IsReadyForMove params are present
{
recoveryPointList = recoveryPointList.Where(
recoveryPoint =>
{
if (targetTier == RecoveryPointTier.VaultArchive)
{
if (recoveryPoint.GetType() == typeof(AzureVmRecoveryPoint) &&
((AzureVmRecoveryPoint)recoveryPoint).RecoveryPointMoveReadinessInfo.ContainsKey(ServiceClientModel.RecoveryPointTierType.ArchivedRP.ToString()))
{
return (((AzureVmRecoveryPoint)recoveryPoint).RecoveryPointMoveReadinessInfo[ServiceClientModel.RecoveryPointTierType.ArchivedRP.ToString()].IsReadyForMove == isReadyForMove);
}

if (recoveryPoint.GetType() == typeof(AzureWorkloadRecoveryPoint) &&
((AzureWorkloadRecoveryPoint)recoveryPoint).RecoveryPointMoveReadinessInfo.ContainsKey(ServiceClientModel.RecoveryPointTierType.ArchivedRP.ToString()))
{
return (((AzureWorkloadRecoveryPoint)recoveryPoint).RecoveryPointMoveReadinessInfo[ServiceClientModel.RecoveryPointTierType.ArchivedRP.ToString()].IsReadyForMove == isReadyForMove);
}
else
{
throw new ArgumentException(Resources.ArchiveNotSupported);
}
}

return false;
}).ToList();
}
return recoveryPointList;
}


/// <summary>
/// Gets Service Client Recovery Point Tier
/// </summary>
public static ServiceClientModel.RecoveryPointTierType GetServiceClientRecoveryPointTier(RecoveryPointTier rpTier)
{
ServiceClientModel.RecoveryPointTierType recoveryPointTierType = ServiceClientModel.RecoveryPointTierType.Invalid;

switch (rpTier)
{
case RecoveryPointTier.VaultArchive:
recoveryPointTierType = ServiceClientModel.RecoveryPointTierType.ArchivedRP;
break;
case RecoveryPointTier.VaultStandard:
recoveryPointTierType = ServiceClientModel.RecoveryPointTierType.HardenedRP;
break;
case RecoveryPointTier.Snapshot:
recoveryPointTierType = ServiceClientModel.RecoveryPointTierType.InstantRP;
break;
default:
break;
}

return recoveryPointTierType;
}

/// <summary>
/// Helper function to convert ps recovery points list model from service response.
/// </summary>
Expand Down Expand Up @@ -158,8 +254,85 @@ public static RecoveryPointBase GetPSAzureVMRecoveryPoint(
recoveryPoint.IsManagedVirtualMachine.Value : false,
OriginalSAEnabled = recoveryPoint.OriginalStorageAccountOption.HasValue ?
recoveryPoint.OriginalStorageAccountOption.Value : false,
RehydrationExpiryTime = (DateTime?)null,
};

if (recoveryPoint.RecoveryPointTierDetails != null)
{
bool isHardenedRP = false;
bool isInstantRecoverable = false;
bool isArchived = false;
bool isRehydrated = false;

foreach(ServiceClientModel.RecoveryPointTierInformation tierInfo in recoveryPoint.RecoveryPointTierDetails)
{
if (tierInfo.Status == ServiceClientModel.RecoveryPointTierStatus.Rehydrated)
{
if (tierInfo.Type == ServiceClientModel.RecoveryPointTierType.ArchivedRP)
{
isRehydrated = true;

rpBase.RehydrationExpiryTime = (tierInfo.ExtendedInfo.ContainsKey("RehydratedRPExpiryTime")) ? DateTime.Parse(tierInfo.ExtendedInfo["RehydratedRPExpiryTime"]) : (DateTime?)null;
}
}

if (tierInfo.Status == ServiceClientModel.RecoveryPointTierStatus.Valid)
{
if (tierInfo.Type == ServiceClientModel.RecoveryPointTierType.InstantRP)
{
isInstantRecoverable = true;
}
if (tierInfo.Type == ServiceClientModel.RecoveryPointTierType.HardenedRP)
{
isHardenedRP = true;
}
if (tierInfo.Type == ServiceClientModel.RecoveryPointTierType.ArchivedRP)
{
isArchived = true;
}
}
}

if ((isHardenedRP && isArchived) || (isRehydrated))
{
rpBase.RecoveryPointTier = RecoveryPointTier.VaultStandardRehydrated;
}
else if (isInstantRecoverable && isHardenedRP)
{
rpBase.RecoveryPointTier = RecoveryPointTier.SnapshotAndVaultStandard;
}
else if(isInstantRecoverable && isArchived)
{
rpBase.RecoveryPointTier = RecoveryPointTier.SnapshotAndVaultArchive;
}
else if (isArchived)
{
rpBase.RecoveryPointTier = RecoveryPointTier.VaultArchive;
}
else if (isInstantRecoverable)
{
rpBase.RecoveryPointTier = RecoveryPointTier.Snapshot;
}
else if (isHardenedRP)
{
rpBase.RecoveryPointTier = RecoveryPointTier.VaultStandard;
}
}

if(recoveryPoint.RecoveryPointMoveReadinessInfo != null)
{
rpBase.RecoveryPointMoveReadinessInfo = new Dictionary<string, RecoveryPointMoveReadinessInfo>();

foreach (var moveInfo in recoveryPoint.RecoveryPointMoveReadinessInfo)
{
RecoveryPointMoveReadinessInfo AzureVmMoveInfo = new RecoveryPointMoveReadinessInfo();
AzureVmMoveInfo.IsReadyForMove = moveInfo.Value.IsReadyForMove;
AzureVmMoveInfo.AdditionalInfo = moveInfo.Value.AdditionalInfo;

rpBase.RecoveryPointMoveReadinessInfo.Add(moveInfo.Key, AzureVmMoveInfo);
}
}

if (rpBase.EncryptionEnabled && recoveryPoint.KeyAndSecret != null)
{
rpBase.KeyAndSecretDetails = new KeyAndSecretDetails()
Expand Down Expand Up @@ -248,8 +421,86 @@ public static RecoveryPointBase GetPSAzureWorkloadRecoveryPoint(
RecoveryPointType = recoveryPoint.Type,
Id = rp.Id,
WorkloadType = item.WorkloadType,
DataDirectoryPaths = recoveryPoint.ExtendedInfo != null ? recoveryPoint.ExtendedInfo.DataDirectoryPaths : null
DataDirectoryPaths = recoveryPoint.ExtendedInfo != null ? recoveryPoint.ExtendedInfo.DataDirectoryPaths : null,
RehydrationExpiryTime = (DateTime?)null
};

if (recoveryPoint.RecoveryPointTierDetails != null)
{
bool isHardenedRP = false;
bool isInstantRecoverable = false;
bool isArchived = false;
bool isRehydrated = false;

foreach (ServiceClientModel.RecoveryPointTierInformation tierInfo in recoveryPoint.RecoveryPointTierDetails)
{
if (tierInfo.Status == ServiceClientModel.RecoveryPointTierStatus.Rehydrated)
{
if (tierInfo.Type == ServiceClientModel.RecoveryPointTierType.ArchivedRP)
{
isRehydrated = true;
rpBase.RehydrationExpiryTime = (tierInfo.ExtendedInfo.ContainsKey("RehydratedRPExpiryTime")) ? DateTime.Parse(tierInfo.ExtendedInfo["RehydratedRPExpiryTime"]) : (DateTime?)null;
}
}

if (tierInfo.Status == ServiceClientModel.RecoveryPointTierStatus.Valid)
{
if (tierInfo.Type == ServiceClientModel.RecoveryPointTierType.InstantRP)
{
isInstantRecoverable = true;
}
if (tierInfo.Type == ServiceClientModel.RecoveryPointTierType.HardenedRP)
{
isHardenedRP = true;
}
if (tierInfo.Type == ServiceClientModel.RecoveryPointTierType.ArchivedRP)
{
isArchived = true;
}
}
}

if ((isHardenedRP && isArchived) || (isRehydrated))
{
rpBase.RecoveryPointTier = RecoveryPointTier.VaultStandardRehydrated;
}
else if (isInstantRecoverable && isHardenedRP)
{
rpBase.RecoveryPointTier = RecoveryPointTier.SnapshotAndVaultStandard;
}
else if (isInstantRecoverable && isArchived)
{
rpBase.RecoveryPointTier = RecoveryPointTier.SnapshotAndVaultArchive;
}
else if (isArchived)
{
rpBase.RecoveryPointTier = RecoveryPointTier.VaultArchive;
}
else if (isInstantRecoverable)
{
rpBase.RecoveryPointTier = RecoveryPointTier.Snapshot;
}
else if (isHardenedRP)
{
rpBase.RecoveryPointTier = RecoveryPointTier.VaultStandard;
}
}


if (recoveryPoint.RecoveryPointMoveReadinessInfo != null)
{
rpBase.RecoveryPointMoveReadinessInfo = new Dictionary<string, RecoveryPointMoveReadinessInfo>();

foreach (var moveInfo in recoveryPoint.RecoveryPointMoveReadinessInfo)
{
RecoveryPointMoveReadinessInfo AzureVmMoveInfo = new RecoveryPointMoveReadinessInfo();
AzureVmMoveInfo.IsReadyForMove = moveInfo.Value.IsReadyForMove;
AzureVmMoveInfo.AdditionalInfo = moveInfo.Value.AdditionalInfo;

rpBase.RecoveryPointMoveReadinessInfo.Add(moveInfo.Key, AzureVmMoveInfo);
}
}

return rpBase;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.3-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.5-preview" />
<PackageReference Include="TimeZoneConverter" Version="3.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
{
/// <summary>
Expand Down Expand Up @@ -63,9 +66,38 @@ public class AzureVmRecoveryPoint : AzureRecoveryPoint
/// </summary>
public bool OriginalSAEnabled { get; set; }

/// <summary>
/// Recovery Type information for Recovery point: "Vault", "Snapshot", "Snapshot and Vault"
/// </summary>
public RecoveryPointTier RecoveryPointTier;

/// <summary>
/// Recovery point move rediness info
/// </summary>
public IDictionary<string, RecoveryPointMoveReadinessInfo> RecoveryPointMoveReadinessInfo;

/// <summary>
/// Rehydration expiry time
/// </summary>
public DateTime? RehydrationExpiryTime;

public AzureVmRecoveryPoint()
{

}
}

public class RecoveryPointMoveReadinessInfo
{
/// <summary>
/// determines the move readiness of a recovery point
/// </summary>
public bool? IsReadyForMove { get; set; }

/// <summary>
/// additional move message from service
/// </summary>
public string AdditionalInfo { get; set; }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
using System;
using System.Collections.Generic;

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
Expand All @@ -23,6 +24,22 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
public class AzureWorkloadRecoveryPoint : AzureRecoveryPoint
{
public IList<SQLDataDirectory> DataDirectoryPaths { get; set; }

/// <summary>
/// Recovery Type information for Recovery point: "Vault", "Snapshot", "Snapshot and Vault"
/// </summary>
public RecoveryPointTier RecoveryPointTier;

/// <summary>
/// Recovery point move rediness info
/// </summary>
public IDictionary<string, RecoveryPointMoveReadinessInfo> RecoveryPointMoveReadinessInfo;

/// <summary>
/// Rehydration expiry time
/// </summary>
public DateTime? RehydrationExpiryTime;

public AzureWorkloadRecoveryPoint()
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ public enum RecoveryPointParams
TargetLocation,
KeyFileDownloadLocation,
FileDownloadLocation,
RestorePointQueryType
RestorePointQueryType,
TargetZone,
SourceTier,
TargetTier,
IsReadyForMove,
RehydrateDuration,
RehydratePriority,
Tier
}

public enum RestoreBackupItemParams
Expand Down
Loading