Skip to content

[RecoveryServices] Adding support for restore item for azure file share #7681

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 4 commits into from
Oct 30, 2018
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 @@ -12,12 +12,13 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
using Microsoft.Rest.Azure;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
using Microsoft.Rest.Azure;
using CmdletModel = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
using ResourceManagerModel = Microsoft.Azure.Management.Internal.Resources.Models;
using ServiceClientModel = Microsoft.Azure.Management.RecoveryServices.Backup.Models;

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers
Expand Down Expand Up @@ -327,5 +328,35 @@ public static List<T> GetPagedList<T>(

return resources;
}

public static List<T> GetPagedRMList<T>(
Func<IPage<T>> listResources, Func<string, IPage<T>> listNext)
where T : ResourceManagerModel.Resource
{
var resources = new List<T>();
string nextLink = null;

var pagedResources = listResources();

foreach (var pagedResource in pagedResources)
{
resources.Add(pagedResource);
}

nextLink = pagedResources.NextPageLink;

while (!string.IsNullOrEmpty(nextLink))
{
pagedResources = listNext(nextLink);
nextLink = pagedResources.NextPageLink;

foreach (var pagedResource in pagedResources)
{
resources.Add(pagedResource);
}
}

return resources;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,26 @@ public enum RecoveryPointParams
public enum RestoreBackupItemParams
{
RecoveryPoint,
StorageAccountId,
StorageAccountLocation,
StorageAccountType,
StorageAccountName,
StorageAccountResourceGroupName
}

public enum RestoreVMBackupItemParams
{
TargetResourceGroupName,
OsaOption
}

public enum RestoreFSBackupItemParams
{
ResolveConflict,
SourceFilePath,
SourceFileType,
TargetStorageAccountName,
TargetFileShareName,
TargetFolder
}

public enum PolicyParams
{
WorkloadType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,22 @@ public enum ILRAction
Extend,
Terminate,
}

/// <summary>
/// Options to resolve conflict for a file share
/// </summary>
public enum RestoreFSResolveConflictOption
{
Overwrite,
Skip
}

/// <summary>
/// Options to select the file type
/// </summary>
public enum SourceFileType
{
File,
Directory
}
}

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 @@ -377,7 +377,7 @@ Please contact Microsoft for further assistance.</value>
<data name="RestoreAzureStorageNotFound" xml:space="preserve">
<value>Storage account not found</value>
</data>
<data name="RestoreDiskIncorrectRegion" xml:space="preserve">
<data name="TriggerRestoreIncorrectRegion" xml:space="preserve">
<value>Storage account location should be same as vault location</value>
</data>
<data name="RestoreDiskMoreThanOneAccFound" xml:space="preserve">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System.Collections.Generic;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS;
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
using System.Collections.Generic;
using CmdletModel = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
using RestAzureNS = Microsoft.Rest.Azure;
using System.Net.Http;

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
using Microsoft.Azure.Management.Internal.Resources.Models;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
using Microsoft.Rest.Azure.OData;
Expand Down Expand Up @@ -147,7 +148,103 @@ public RestAzureNS.AzureOperationResponse TriggerBackup()

public RestAzureNS.AzureOperationResponse TriggerRestore()
{
throw new NotImplementedException();
string vaultName = (string)ProviderData[VaultParams.VaultName];
string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
string vaultLocation = (string)ProviderData[VaultParams.VaultLocation];
CmdletModel.AzureFileShareRecoveryPoint recoveryPoint = ProviderData[RestoreBackupItemParams.RecoveryPoint]
as CmdletModel.AzureFileShareRecoveryPoint;
string storageAccountName = ProviderData[RestoreBackupItemParams.StorageAccountName].ToString();
string storageAccountResourceGroupName = ProviderData.ContainsKey(RestoreBackupItemParams.StorageAccountResourceGroupName) ?
ProviderData[RestoreBackupItemParams.StorageAccountResourceGroupName].ToString() : null;
string copyOptions = (string)ProviderData[RestoreFSBackupItemParams.ResolveConflict];
string sourceFilePath = ProviderData.ContainsKey(RestoreFSBackupItemParams.SourceFilePath) ?
(string)ProviderData[RestoreFSBackupItemParams.SourceFilePath] : null;
string sourceFileType = ProviderData.ContainsKey(RestoreFSBackupItemParams.SourceFileType) ?
(string)ProviderData[RestoreFSBackupItemParams.SourceFileType] : null;
string targetStorageAccountName =
ProviderData.ContainsKey(RestoreFSBackupItemParams.TargetStorageAccountName) ?
(string)ProviderData[RestoreFSBackupItemParams.TargetStorageAccountName] : null;
string targetFileShareName = ProviderData.ContainsKey(RestoreFSBackupItemParams.TargetFileShareName) ?
(string)ProviderData[RestoreFSBackupItemParams.TargetFileShareName] : null;
string targetFolder = ProviderData.ContainsKey(RestoreFSBackupItemParams.TargetFolder) ?
(string)ProviderData[RestoreFSBackupItemParams.TargetFolder] : null;

GenericResource storageAccountResource = ServiceClientAdapter.GetStorageAccountResource(storageAccountName);
GenericResource targetStorageAccountResource = null;
string targetStorageAccountLocation = null;
if (targetStorageAccountName != null)
{
targetStorageAccountResource = ServiceClientAdapter.GetStorageAccountResource(targetStorageAccountName);
targetStorageAccountLocation = targetStorageAccountResource.Location;
}

List<RestoreFileSpecs> restoreFileSpecs = null;
TargetAFSRestoreInfo targetDetails = null;
RestoreFileSpecs restoreFileSpec = new RestoreFileSpecs();
AzureFileShareRestoreRequest restoreRequest = new AzureFileShareRestoreRequest();
restoreRequest.CopyOptions = copyOptions;
restoreRequest.SourceResourceId = storageAccountResource.Id;
if (sourceFilePath != null)
{
restoreFileSpec.Path = sourceFilePath;
restoreFileSpec.FileSpecType = sourceFileType;
restoreRequest.RestoreRequestType = RestoreRequestType.ItemLevelRestore;
if (targetFolder != null)
{
//scenario : item level restore for alternate location
restoreFileSpec.TargetFolderPath = targetFolder;
targetDetails = new TargetAFSRestoreInfo();
targetDetails.Name = targetFileShareName;
targetDetails.TargetResourceId = targetStorageAccountResource.Id;
restoreRequest.RecoveryType = RecoveryType.AlternateLocation;
}
else
{
//scenario : item level restore for original location
restoreFileSpec.TargetFolderPath = null;
restoreRequest.RecoveryType = RecoveryType.OriginalLocation;
}

restoreFileSpecs = new List<RestoreFileSpecs>();
restoreFileSpecs.Add(restoreFileSpec);
}
else
{
restoreRequest.RestoreRequestType = RestoreRequestType.FullShareRestore;
if (targetFolder != null)
{
//scenario : full level restore for alternate location
restoreFileSpec.Path = null;
restoreFileSpec.TargetFolderPath = targetFolder;
restoreFileSpec.FileSpecType = null;
restoreFileSpecs = new List<RestoreFileSpecs>();
restoreFileSpecs.Add(restoreFileSpec);
targetDetails = new TargetAFSRestoreInfo();
targetDetails.Name = targetFileShareName;
targetDetails.TargetResourceId = targetStorageAccountResource.Id;
restoreRequest.RecoveryType = RecoveryType.AlternateLocation;
}
else
{
//scenario : full level restore for original location
restoreRequest.RecoveryType = RecoveryType.OriginalLocation;
}
}

restoreRequest.RestoreFileSpecs = restoreFileSpecs;
restoreRequest.TargetDetails = targetDetails;

RestoreRequestResource triggerRestoreRequest = new RestoreRequestResource();
triggerRestoreRequest.Properties = restoreRequest;

var response = ServiceClientAdapter.RestoreDisk(
recoveryPoint,
targetStorageAccountLocation = targetStorageAccountLocation ?? storageAccountResource.Location,
triggerRestoreRequest,
vaultName: vaultName,
resourceGroupName: resourceGroupName,
vaultLocation: vaultLocation);
return response;
}

public ProtectedItemResource GetProtectedItem()
Expand Down Expand Up @@ -665,7 +762,7 @@ private RestAzureNS.AzureOperationResponse EnableOrModifyProtection(bool disable
properties.PolicyId = policy.Id;
properties.SourceResourceId = sourceResourceId;
}
else if(disableWithRetentionData)
else if (disableWithRetentionData)
{
//Disable protection while retaining backup data
ValidateAzureFileShareDisableProtectionRequest(itemBase);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
using Microsoft.Rest.Azure.OData;
using System;
using System.Collections.Generic;
using System.Linq;
using CmdletModel = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
using RestAzureNS = Microsoft.Rest.Azure;
using ServiceClientModel = Microsoft.Azure.Management.RecoveryServices.Backup.Models;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
using Microsoft.Rest.Azure.OData;
using System;
using System.Collections.Generic;
using RestAzureNS = Microsoft.Rest.Azure;
using ServiceClientModel = Microsoft.Azure.Management.RecoveryServices.Backup.Models;

Expand All @@ -37,7 +37,8 @@ public class DpmPsBackupProvider : IPsBackupProvider
/// <param name="providerData">Data from the cmdlet layer intended for the provider</param>
/// <param name="serviceClientAdapter">Service client adapter for communicating with the backend service</param>
public void Initialize(
Dictionary<Enum, object> providerData, ServiceClientAdapter serviceClientAdapter)
Dictionary<Enum, object> providerData,
ServiceClientAdapter serviceClientAdapter)
{
ProviderData = providerData;
ServiceClientAdapter = serviceClientAdapter;
Expand Down
Loading