Skip to content

Added -Vault parameter to RecoveryServices.Backup cmdlets #6327

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 29 commits into from
Jun 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d77ed83
Added -Vault parameter to RecoveryServices.Backup cmdlets
May 29, 2018
c32027a
Updating changelog
May 29, 2018
0d1834f
Updating help files
May 30, 2018
eb16570
Updating help
May 31, 2018
063a140
Added test case for Set Vault Context cmdlet usage.
Jun 5, 2018
5463a43
Undoing unwanted changes to tools/AzureRM/AzureRM.psm1
Jun 6, 2018
ae300df
Using VaultId and VaultLocation instead of Vault.
Jun 11, 2018
871efa6
Fixing test failures
Jun 11, 2018
3075382
Moved VaultLocation to Restore cmdlet only.
Jun 12, 2018
694ad97
Update Backup-AzureRmRecoveryServicesBackupItem.md
Jun 12, 2018
7adc446
Update Disable-AzureRmRecoveryServicesBackupProtection.md
Jun 12, 2018
7cf4396
Update Disable-AzureRmRecoveryServicesBackupRPMountScript.md
Jun 12, 2018
1a283ea
Update Wait-AzureRmRecoveryServicesBackupJob.md
Jun 12, 2018
9dcfc92
Update Unregister-AzureRmRecoveryServicesBackupManagementServer.md
Jun 12, 2018
5718f8c
Update Get-AzureRmRecoveryServicesBackupProtectionPolicy.md
Jun 12, 2018
f85a3a5
Update Enable-AzureRmRecoveryServicesBackupProtection.md
Jun 12, 2018
4afb765
Update Get-AzureRmRecoveryServicesBackupJob.md
Jun 12, 2018
abc57c2
Update Get-AzureRmRecoveryServicesBackupContainer.md
Jun 12, 2018
d2278e8
Update Unregister-AzureRmRecoveryServicesBackupContainer.md
Jun 12, 2018
237c3ec
Update Restore-AzureRmRecoveryServicesBackupItem.md
Jun 12, 2018
17a71a8
Update Set-AzureRmRecoveryServicesBackupProtectionPolicy.md
Jun 12, 2018
997e8d0
Update Get-AzureRmRecoveryServicesBackupItem.md
Jun 12, 2018
9c3bc4d
Update Get-AzureRmRecoveryServicesBackupJobDetails.md
Jun 12, 2018
4863996
Update Get-AzureRmRecoveryServicesBackupRPMountScript.md
Jun 12, 2018
104dbb4
Update Get-AzureRmRecoveryServicesBackupManagementServer.md
Jun 12, 2018
da1d375
Update Get-AzureRmRecoveryServicesBackupRecoveryPoint.md
Jun 12, 2018
2b27d27
Update New-AzureRmRecoveryServicesBackupProtectionPolicy.md
Jun 12, 2018
e151ff4
Update Remove-AzureRmRecoveryServicesBackupProtectionPolicy.md
Jun 12, 2018
bc796e1
Update Stop-AzureRmRecoveryServicesBackupJob.md
Jun 12, 2018
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 @@ -14,6 +14,13 @@

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
{
public enum VaultParams
{
VaultName,
ResourceGroupName,
VaultLocation,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see this used anywhere - is it needed?

Copy link
Author

Choose a reason for hiding this comment

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

}

public enum ContainerParams
{
Vault,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
using CmdletModel = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
using RestAzureNS = Microsoft.Rest.Azure;
using ServiceClientModel = Microsoft.Azure.Management.RecoveryServices.Backup.Models;
using System.Net.Http;

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel
{
Expand Down Expand Up @@ -70,6 +69,8 @@ public RestAzureNS.AzureOperationResponse EnableProtection()
/// <returns>The job response returned from the service</returns>
public RestAzureNS.AzureOperationResponse DisableProtection()
{
string vaultName = (string)ProviderData[VaultParams.VaultName];
string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
bool deleteBackupData = (bool)ProviderData[ItemParams.DeleteBackupData];

ItemBase itemBase = (ItemBase)ProviderData[ItemParams.Item];
Expand All @@ -84,8 +85,10 @@ public RestAzureNS.AzureOperationResponse DisableProtection()
if (deleteBackupData)
{
return ServiceClientAdapter.DeleteProtectedItem(
containerUri,
protectedItemUri);
containerUri,
protectedItemUri,
vaultName: vaultName,
resourceGroupName: resourceGroupName);
}
else
{
Expand Down Expand Up @@ -126,6 +129,8 @@ public void RevokeItemLevelRecoveryAccess()
/// <returns>Recovery point detail as returned by the service</returns>
public RecoveryPointBase GetRecoveryPointDetails()
{
string vaultName = (string)ProviderData[VaultParams.VaultName];
string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
AzureSqlItem item = ProviderData[RecoveryPointParams.Item]
as AzureSqlItem;

Expand All @@ -136,7 +141,11 @@ public RecoveryPointBase GetRecoveryPointDetails()
string protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, item.Id);

var rpResponse = ServiceClientAdapter.GetRecoveryPointDetails(
containerUri, protectedItemName, recoveryPointId);
containerUri,
protectedItemName,
recoveryPointId,
vaultName: vaultName,
resourceGroupName: resourceGroupName);
return RecoveryPointConversions.GetPSAzureRecoveryPoints(rpResponse, item);
}

Expand All @@ -146,6 +155,8 @@ public RecoveryPointBase GetRecoveryPointDetails()
/// <returns>List of recovery point PowerShell model objects</returns>
public List<RecoveryPointBase> ListRecoveryPoints()
{
string vaultName = (string)ProviderData[VaultParams.VaultName];
string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
DateTime startDate = (DateTime)(ProviderData[RecoveryPointParams.StartDate]);
DateTime endDate = (DateTime)(ProviderData[RecoveryPointParams.EndDate]);
AzureSqlItem item = ProviderData[RecoveryPointParams.Item]
Expand All @@ -172,7 +183,11 @@ public List<RecoveryPointBase> ListRecoveryPoints()
queryFilter.Filter = queryFilterString;

List<RecoveryPointResource> rpListResponse = ServiceClientAdapter.GetRecoveryPoints(
containerUri, protectedItemName, queryFilter);
containerUri,
protectedItemName,
queryFilter,
vaultName: vaultName,
resourceGroupName: resourceGroupName);
return RecoveryPointConversions.GetPSAzureRecoveryPoints(rpListResponse, item);
}

Expand All @@ -182,6 +197,8 @@ public List<RecoveryPointBase> ListRecoveryPoints()
/// <returns>Created policy object as returned by the service</returns>
public ProtectionPolicyResource CreatePolicy()
{
string vaultName = (string)ProviderData[VaultParams.VaultName];
string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
string policyName = (string)ProviderData[PolicyParams.PolicyName];
CmdletModel.WorkloadType workloadType =
(CmdletModel.WorkloadType)ProviderData[PolicyParams.WorkloadType];
Expand All @@ -197,7 +214,7 @@ public ProtectionPolicyResource CreatePolicy()
Logger.Instance.WriteDebug("Validation of Retention policy is successful");

// construct Hydra policy request
ProtectionPolicyResource hydraRequest = new ProtectionPolicyResource()
ProtectionPolicyResource protectionPolicyResource = new ProtectionPolicyResource()
{
Properties = new AzureSqlProtectionPolicy()
{
Expand All @@ -207,8 +224,10 @@ public ProtectionPolicyResource CreatePolicy()
};

return ServiceClientAdapter.CreateOrUpdateProtectionPolicy(
policyName,
hydraRequest).Body;
policyName,
protectionPolicyResource,
vaultName: vaultName,
resourceGroupName: resourceGroupName).Body;
}

/// <summary>
Expand All @@ -217,6 +236,8 @@ public ProtectionPolicyResource CreatePolicy()
/// <returns>Modified policy object as returned by the service</returns>
public RestAzureNS.AzureOperationResponse<ProtectionPolicyResource> ModifyPolicy()
{
string vaultName = (string)ProviderData[VaultParams.VaultName];
string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
RetentionPolicyBase retentionPolicy =
ProviderData.ContainsKey(PolicyParams.RetentionPolicy) ?
(RetentionPolicyBase)ProviderData[PolicyParams.RetentionPolicy] :
Expand All @@ -241,7 +262,7 @@ public RestAzureNS.AzureOperationResponse<ProtectionPolicyResource> ModifyPolicy

CmdletModel.SimpleRetentionPolicy sqlRetentionPolicy =
(CmdletModel.SimpleRetentionPolicy)((AzureSqlPolicy)policy).RetentionPolicy;
ProtectionPolicyResource hydraRequest = new ProtectionPolicyResource()
ProtectionPolicyResource protectionPolicyResource = new ProtectionPolicyResource()
{
Properties = new AzureSqlProtectionPolicy()
{
Expand All @@ -250,8 +271,11 @@ public RestAzureNS.AzureOperationResponse<ProtectionPolicyResource> ModifyPolicy
}
};

return ServiceClientAdapter.CreateOrUpdateProtectionPolicy(policy.Name,
hydraRequest);
return ServiceClientAdapter.CreateOrUpdateProtectionPolicy(
policy.Name,
protectionPolicyResource,
vaultName: vaultName,
resourceGroupName: resourceGroupName);
}

/// <summary>
Expand All @@ -260,15 +284,19 @@ public RestAzureNS.AzureOperationResponse<ProtectionPolicyResource> ModifyPolicy
/// <returns>List of protection containers</returns>
public List<ContainerBase> ListProtectionContainers()
{
string name = (string)this.ProviderData[ContainerParams.Name];
string vaultName = (string)ProviderData[VaultParams.VaultName];
string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
string name = (string)ProviderData[ContainerParams.Name];

ODataQuery<BMSContainerQueryObject> queryParams =
new ODataQuery<BMSContainerQueryObject>(
q => q.BackupManagementType
== ServiceClientModel.BackupManagementType.AzureSql);


var listResponse = ServiceClientAdapter.ListContainers(queryParams);
var listResponse = ServiceClientAdapter.ListContainers(
queryParams,
vaultName: vaultName,
resourceGroupName: resourceGroupName);

List<ContainerBase> containerModels =
ConversionHelpers.GetContainerModelList(listResponse);
Expand Down Expand Up @@ -317,6 +345,8 @@ public RetentionPolicyBase GetDefaultRetentionPolicyObject()
/// <returns>List of protected items</returns>
public List<ItemBase> ListProtectedItems()
{
string vaultName = (string)ProviderData[VaultParams.VaultName];
string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
ContainerBase container = (ContainerBase)ProviderData[ItemParams.Container];
string name = (string)ProviderData[ItemParams.AzureVMName];
ItemProtectionStatus protectionStatus =
Expand All @@ -334,10 +364,13 @@ public List<ItemBase> ListProtectedItems()

List<ProtectedItemResource> protectedItems = new List<ProtectedItemResource>();
string skipToken = null;
var listResponse = ServiceClientAdapter.ListProtectedItem(queryParams, skipToken);
var listResponse = ServiceClientAdapter.ListProtectedItem(
queryParams,
skipToken,
vaultName: vaultName,
resourceGroupName: resourceGroupName);
protectedItems.AddRange(listResponse);


// 1. Filter by container
if (container != null)
{
Expand Down Expand Up @@ -379,7 +412,11 @@ public List<ItemBase> ListProtectedItems()
HelperUtils.GetProtectedItemUri(dictionary, protectedItems[i].Id);

var getResponse = ServiceClientAdapter.GetProtectedItem(
containerUri, protectedItemUri, getItemQueryParams);
containerUri,
protectedItemUri,
getItemQueryParams,
vaultName: vaultName,
resourceGroupName: resourceGroupName);
protectedItemGetResponses.Add(getResponse.Body);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
using Microsoft.Rest.Azure.OData;
using RestAzureNS = Microsoft.Rest.Azure;
using ServiceClientModel = Microsoft.Azure.Management.RecoveryServices.Backup.Models;
using System.Net.Http;

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel
{
Expand Down Expand Up @@ -113,12 +112,17 @@ public void RevokeItemLevelRecoveryAccess()
/// <returns></returns>
public List<BackupEngineBase> ListBackupManagementServers()
{
string vaultName = (string)ProviderData[VaultParams.VaultName];
string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
string name = (string)ProviderData[ContainerParams.Name];

ODataQuery<ServiceClientModel.BMSBackupEnginesQueryObject> queryParams =
new ODataQuery<ServiceClientModel.BMSBackupEnginesQueryObject>();

var listResponse = ServiceClientAdapter.ListBackupEngines(queryParams);
var listResponse = ServiceClientAdapter.ListBackupEngines(
queryParams,
vaultName: vaultName,
resourceGroupName: resourceGroupName);

List<BackupEngineBase> backupEngineModels = ConversionHelpers.GetBackupEngineModelList(listResponse);

Expand Down
Loading