Skip to content

Commit

Permalink
Added unmanaged vm restore warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Sambit Rath committed Mar 20, 2020
1 parent ce24431 commit ce58780
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public enum RestoreVMBackupItemParams
TargetResourceGroupName,
OsaOption,
RestoreDiskList,
RestoreOnlyOSDisk
RestoreOnlyOSDisk,
RestoreAsUnmanagedDisks
}

public enum RestoreFSBackupItemParams
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -592,4 +592,10 @@ Please contact Microsoft for further assistance.</value>
<data name="InclusionListRedundantError" xml:space="preserve">
<value>Both Inclusion and Exclusion lists provided. Please provide only one of them.</value>
</data>
<data name="TargetRGUnmanagedRestoreDuplicateParamsException" xml:space="preserve">
<value>Both RestoreAsUnmanagedDisks and TargetResourceGroupName can't be spceified. Please give Only one parameter and retry.</value>
</data>
<data name="UnmanagedVMRestoreWarning" xml:space="preserve">
<value>The disks of the managed VM will be restored as unmanaged since TargetResourceGroupName parameter is not provided. This will NOT leverage the instant restore functionality and hence can be significantly slow based on given storage account. To leverage instant restore, provide the TargetResourceGroupName parameter. Otherwise, provide the intent next time by passing the RestoreAsUnmanagedDisks parameter</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,5 @@
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.0.1-preview" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>


</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
bool osaOption = (bool)ProviderData[RestoreVMBackupItemParams.OsaOption];
string[] restoreDiskList = (string[])ProviderData[RestoreVMBackupItemParams.RestoreDiskList];
SwitchParameter restoreOnlyOSDisk = (SwitchParameter)ProviderData[RestoreVMBackupItemParams.RestoreOnlyOSDisk];
SwitchParameter restoreAsUnmanagedDisks = (SwitchParameter)ProviderData[RestoreVMBackupItemParams.RestoreAsUnmanagedDisks];

Dictionary<UriEnums, string> uriDict = HelperUtils.ParseUri(rp.Id);
string containerUri = HelperUtils.GetContainerUri(uriDict, rp.Id);
Expand All @@ -405,11 +406,22 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
throw new Exception(string.Format(Resources.RestoreDiskStorageTypeError, vmType));
}

if(targetResourceGroupName != null && restoreAsUnmanagedDisks.IsPresent)
{
throw new Exception(Resources.TargetRGUnmanagedRestoreDuplicateParamsException);
}

if (targetResourceGroupName != null && rp.IsManagedVirtualMachine == false)
{
Logger.Instance.WriteWarning(Resources.UnManagedBackupVmWarning);
}

if(rp.IsManagedVirtualMachine == true && targetResourceGroupName == null
&& restoreAsUnmanagedDisks.IsPresent == false)
{
Logger.Instance.WriteWarning(Resources.UnmanagedVMRestoreWarning);
}

IList<int?> restoreDiskLUNS;
if(restoreOnlyOSDisk.IsPresent)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,26 @@ public class RestoreAzureRmRecoveryServicesBackupItem : RSBackupVaultCmdletBase
HelpMessage = ParamHelpMsgs.RestoreVM.OsaOption)]
public SwitchParameter UseOriginalStorageAccount { get; set; }


/// <summary>
/// Use this switch to restore only OS disks of the backed up VM
/// </summary>
[Parameter(Mandatory = false, ParameterSetName = AzureVMParameterSet,
HelpMessage = "Restore OS Disk only")]
HelpMessage = ParamHelpMsgs.RestoreVM.RestoreOnlyOSDisk)]
public SwitchParameter RestoreOnlyOSDisk { get; set; }

/// <summary>
/// Specify which disks to recover of the backed up VM
/// </summary>
[Parameter(Mandatory = false, ParameterSetName = AzureVMParameterSet,
HelpMessage = "Specify disk list to be restored")]
HelpMessage = ParamHelpMsgs.RestoreVM.RestoreDiskList)]
public string[] RestoreDiskList { get; set; }

/// <summary>
/// Use this switch to specify to restore as unmanaged disks
/// </summary>
[Parameter(Mandatory = false, ParameterSetName = AzureVMParameterSet,
HelpMessage = ParamHelpMsgs.RestoreVM.RestoreAsUnmanagedDisks)]
public SwitchParameter RestoreAsUnmanagedDisks { get; set; }

public override void ExecuteCmdlet()
{
Expand All @@ -174,7 +185,7 @@ public override void ExecuteCmdlet()
providerParameters.Add(RestoreWLBackupItemParams.WLRecoveryConfig, WLRecoveryConfig);
providerParameters.Add(RestoreVMBackupItemParams.RestoreDiskList, RestoreDiskList);
providerParameters.Add(RestoreVMBackupItemParams.RestoreOnlyOSDisk, RestoreOnlyOSDisk);

providerParameters.Add(RestoreVMBackupItemParams.RestoreAsUnmanagedDisks, RestoreAsUnmanagedDisks);

if (StorageAccountName != null)
{
Expand Down
3 changes: 3 additions & 0 deletions src/RecoveryServices/RecoveryServices.Backup/ParamHelpMsgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ internal static class RestoreVM
{
public const string TargetResourceGroupName = "The resource group to which the managed disks are restored. This parameter is mandatory for backup of VM with managed disks";
public const string OsaOption = "Use this switch if the disks from the recovery point are to be restored to their original storage accounts";
public const string RestoreOnlyOSDisk = "Use this switch to restore only OS disks of a backed up VM";
public const string RestoreDiskList = "Specify which disks to recover of the backed up VM";
public const string RestoreAsUnmanagedDisks = "Use this switch to specify to restore as unmanaged disks";
}

internal static class RestoreFS
Expand Down

0 comments on commit ce58780

Please sign in to comment.