Skip to content

Commit 6451aa7

Browse files
authored
Merge pull request #4834 from MabOneSdk/ilr
Added cmdlets instant file recovery and enhanced tests
2 parents 8be69fa + fe7fec4 commit 6451aa7

File tree

140 files changed

+1944419
-438538
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+1944419
-438538
lines changed

src/ResourceManager/Common/Commands.ScenarioTests.ResourceManager.Common/AzureRM.Storage.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ function Get-AzureRmStorageAccount
2222
}
2323
$sa = $getTask.Result
2424

25-
if($sa -ne $null)
26-
{
27-
$id = "/subscriptions/" + $context.Subscription.Id + "/resourceGroups/"+ $ResourceGroupName + "/providers/Microsoft.Storage/storageAccounts/" + $Name
28-
$account = Get-StorageAccount $ResourceGroupName $Name $id
29-
Write-Output $account
30-
}
25+
if($sa -ne $null)
26+
{
27+
$id = "/subscriptions/" + $context.Subscription.Id + "/resourceGroups/"+ $ResourceGroupName + "/providers/Microsoft.Storage/storageAccounts/" + $Name
28+
$account = Get-StorageAccount $ResourceGroupName $Name $id
29+
Write-Output $account
30+
}
3131
}
3232
END {}
3333

src/ResourceManager/RecoveryServices.Backup/AzureRM.RecoveryServices.Backup.psd1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ CmdletsToExport = 'Backup-AzureRmRecoveryServicesBackupItem',
9393
'Set-AzureRmRecoveryServicesBackupProtectionPolicy',
9494
'Get-AzureRmRecoveryServicesBackupRecoveryPoint',
9595
'Restore-AzureRmRecoveryServicesBackupItem',
96-
'Unregister-AzureRmRecoveryServicesBackupManagementServer'
96+
'Unregister-AzureRmRecoveryServicesBackupManagementServer',
97+
'Get-AzureRmRecoveryServicesBackupRPMountScript',
98+
'Disable-AzureRmRecoveryServicesBackupRPMountScript'
9799

98100
# Variables to export from this module
99101
# VariablesToExport = @()

src/ResourceManager/RecoveryServices.Backup/ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* Added cmdlets to perform instant file recovery.
22+
* Updated RecoveryServices.Backup SDK version to the latest
23+
* Updated tests for the Azure VM workload so that, all setups needed for test runs are done by the tests themselves.
24+
* Fixes https://github.com/Azure/azure-powershell/issues/3164
2125

2226
## Version 3.4.1
2327

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Helpers/Commands.RecoveryServices.Backup.Helpers.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
<Reference Include="Microsoft.Azure.Common">
4141
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.dll</HintPath>
4242
</Reference>
43-
<Reference Include="Microsoft.Azure.Management.RecoveryServices.Backup, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
43+
<Reference Include="Microsoft.Azure.Management.RecoveryServices.Backup, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
4444
<SpecificVersion>False</SpecificVersion>
45-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.Backup.1.1.2-preview\lib\net45\Microsoft.Azure.Management.RecoveryServices.Backup.dll</HintPath>
45+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.Backup.2.1.0-preview\lib\net452\Microsoft.Azure.Management.RecoveryServices.Backup.dll</HintPath>
4646
</Reference>
4747
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
4848
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.2.3.10\lib\net452\Microsoft.Rest.ClientRuntime.dll</HintPath>

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Helpers/Conversions/ConversionHelpers.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,11 @@ public static PolicyBase GetPolicyModel(ServiceClientModel.ProtectionPolicyResou
160160
iaasPolicyModel.WorkloadType = WorkloadType.AzureVM;
161161
iaasPolicyModel.BackupManagementType = BackupManagementType.AzureVM;
162162
iaasPolicyModel.RetentionPolicy = PolicyHelpers.GetPSLongTermRetentionPolicy((ServiceClientModel.LongTermRetentionPolicy)
163-
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy);
163+
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy,
164+
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).TimeZone);
164165
iaasPolicyModel.SchedulePolicy = PolicyHelpers.GetPSSimpleSchedulePolicy((ServiceClientModel.SimpleSchedulePolicy)
165-
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).SchedulePolicy);
166+
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).SchedulePolicy,
167+
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).TimeZone);
166168
}
167169
else if (serviceClientResponse.Properties.GetType() ==
168170
typeof(ServiceClientModel.AzureSqlProtectionPolicy))
@@ -187,7 +189,7 @@ public static PolicyBase GetPolicyModel(ServiceClientModel.ProtectionPolicyResou
187189
ServiceClientModel.SimpleRetentionPolicy azureSqlRetentionPolicy =
188190
(ServiceClientModel.SimpleRetentionPolicy)azureSqlPolicy.RetentionPolicy;
189191
sqlPolicyModel.RetentionPolicy =
190-
PolicyHelpers.GetPSSimpleRetentionPolicy(azureSqlRetentionPolicy);
192+
PolicyHelpers.GetPSSimpleRetentionPolicy(azureSqlRetentionPolicy, null);
191193
}
192194
else
193195
{

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Helpers/Conversions/JobConversions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,13 @@ public static string GetLastIdFromFullId(string fullId)
193193
/// <summary>
194194
/// Helper function to get job type from ps backup management type.
195195
/// </summary>
196-
public static BackupManagementType GetJobTypeForService(
196+
public static string GetJobTypeForService(
197197
CmdletModel.BackupManagementType mgmtType)
198198
{
199199
switch (mgmtType)
200200
{
201201
case CmdletModel.BackupManagementType.AzureVM:
202-
return BackupManagementType.AzureIaasVM;
202+
return BackupManagementType.AzureIaasVM.ToString();
203203
default:
204204
throw new Exception("Invalid BackupManagementType provided: " + mgmtType);
205205
}

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Helpers/Conversions/RetentionPolicyConversions.cs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.Collections.Generic;
1717
using System.Linq;
1818
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
19+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
1920
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
2021
using ServiceClientModel = Microsoft.Azure.Management.RecoveryServices.Backup.Models;
2122

@@ -34,7 +35,7 @@ public partial class PolicyHelpers
3435
/// Helper function to convert ps long term retention policy from service response.
3536
/// </summary>
3637
public static LongTermRetentionPolicy GetPSLongTermRetentionPolicy(
37-
ServiceClientModel.LongTermRetentionPolicy serviceClientRetPolicy)
38+
ServiceClientModel.LongTermRetentionPolicy serviceClientRetPolicy, string timeZone)
3839
{
3940
if (serviceClientRetPolicy == null)
4041
{
@@ -46,25 +47,25 @@ public static LongTermRetentionPolicy GetPSLongTermRetentionPolicy(
4647
if (serviceClientRetPolicy.DailySchedule != null)
4748
{
4849
ltrPolicy.IsDailyScheduleEnabled = true;
49-
ltrPolicy.DailySchedule = GetPSLTRDailySchedule(serviceClientRetPolicy.DailySchedule);
50+
ltrPolicy.DailySchedule = GetPSLTRDailySchedule(serviceClientRetPolicy.DailySchedule, timeZone);
5051
}
5152

5253
if (serviceClientRetPolicy.WeeklySchedule != null)
5354
{
5455
ltrPolicy.IsWeeklyScheduleEnabled = true;
55-
ltrPolicy.WeeklySchedule = GetPSLTRWeeklySchedule(serviceClientRetPolicy.WeeklySchedule);
56+
ltrPolicy.WeeklySchedule = GetPSLTRWeeklySchedule(serviceClientRetPolicy.WeeklySchedule, timeZone);
5657
}
5758

5859
if (serviceClientRetPolicy.MonthlySchedule != null)
5960
{
6061
ltrPolicy.IsMonthlyScheduleEnabled = true;
61-
ltrPolicy.MonthlySchedule = GetPSLTRMonthlySchedule(serviceClientRetPolicy.MonthlySchedule);
62+
ltrPolicy.MonthlySchedule = GetPSLTRMonthlySchedule(serviceClientRetPolicy.MonthlySchedule, timeZone);
6263
}
6364

6465
if (serviceClientRetPolicy.YearlySchedule != null)
6566
{
6667
ltrPolicy.IsYearlyScheduleEnabled = true;
67-
ltrPolicy.YearlySchedule = GetPSLTRYearlySchedule(serviceClientRetPolicy.YearlySchedule);
68+
ltrPolicy.YearlySchedule = GetPSLTRYearlySchedule(serviceClientRetPolicy.YearlySchedule, timeZone);
6869
}
6970

7071
// safe side validate
@@ -74,7 +75,7 @@ public static LongTermRetentionPolicy GetPSLongTermRetentionPolicy(
7475
}
7576

7677
public static SimpleRetentionPolicy GetPSSimpleRetentionPolicy(
77-
ServiceClientModel.SimpleRetentionPolicy hydraRetPolicy)
78+
ServiceClientModel.SimpleRetentionPolicy hydraRetPolicy, string timeZone)
7879
{
7980
if (hydraRetPolicy == null)
8081
{
@@ -231,7 +232,8 @@ private static int GetRetentionDurationInYears(ServiceClientModel.RetentionDurat
231232
return yearsCount;
232233
}
233234

234-
private static DailyRetentionSchedule GetPSLTRDailySchedule(ServiceClientModel.DailyRetentionSchedule serviceClientDaily)
235+
private static DailyRetentionSchedule GetPSLTRDailySchedule(ServiceClientModel.DailyRetentionSchedule serviceClientDaily,
236+
string timeZone)
235237
{
236238
if (serviceClientDaily == null)
237239
{
@@ -241,12 +243,13 @@ private static DailyRetentionSchedule GetPSLTRDailySchedule(ServiceClientModel.D
241243
DailyRetentionSchedule psDaily = new DailyRetentionSchedule();
242244

243245
psDaily.DurationCountInDays = GetRetentionDurationInDays(serviceClientDaily.RetentionDuration);
244-
psDaily.RetentionTimes = ParseDateTimesToUTC(serviceClientDaily.RetentionTimes);
246+
psDaily.RetentionTimes = ParseDateTimesToUTC(serviceClientDaily.RetentionTimes, timeZone);
245247

246248
return psDaily;
247249
}
248250

249-
private static WeeklyRetentionSchedule GetPSLTRWeeklySchedule(ServiceClientModel.WeeklyRetentionSchedule serviceClientWeekly)
251+
private static WeeklyRetentionSchedule GetPSLTRWeeklySchedule(ServiceClientModel.WeeklyRetentionSchedule serviceClientWeekly,
252+
string timeZone)
250253
{
251254
if (serviceClientWeekly == null)
252255
{
@@ -256,15 +259,16 @@ private static WeeklyRetentionSchedule GetPSLTRWeeklySchedule(ServiceClientModel
256259
WeeklyRetentionSchedule psWeekly = new WeeklyRetentionSchedule();
257260

258261
psWeekly.DurationCountInWeeks = GetRetentionDurationInWeeks(serviceClientWeekly.RetentionDuration);
259-
psWeekly.RetentionTimes = ParseDateTimesToUTC(serviceClientWeekly.RetentionTimes);
262+
psWeekly.RetentionTimes = ParseDateTimesToUTC(serviceClientWeekly.RetentionTimes, timeZone);
260263
psWeekly.DaysOfTheWeek =
261264
HelperUtils.EnumListConverter<ServiceClientModel.DayOfWeek?, DayOfWeek>(
262265
serviceClientWeekly.DaysOfTheWeek);
263266

264267
return psWeekly;
265268
}
266269

267-
private static MonthlyRetentionSchedule GetPSLTRMonthlySchedule(ServiceClientModel.MonthlyRetentionSchedule serviceClientMonthly)
270+
private static MonthlyRetentionSchedule GetPSLTRMonthlySchedule(ServiceClientModel.MonthlyRetentionSchedule serviceClientMonthly,
271+
string timeZone)
268272
{
269273
if (serviceClientMonthly == null)
270274
{
@@ -274,7 +278,7 @@ private static MonthlyRetentionSchedule GetPSLTRMonthlySchedule(ServiceClientMod
274278
MonthlyRetentionSchedule psMonthly = new MonthlyRetentionSchedule();
275279

276280
psMonthly.DurationCountInMonths = GetRetentionDurationInMonths(serviceClientMonthly.RetentionDuration);
277-
psMonthly.RetentionTimes = ParseDateTimesToUTC(serviceClientMonthly.RetentionTimes);
281+
psMonthly.RetentionTimes = ParseDateTimesToUTC(serviceClientMonthly.RetentionTimes, timeZone);
278282
psMonthly.RetentionScheduleFormatType =
279283
serviceClientMonthly.RetentionScheduleFormatType.ToEnum<RetentionScheduleFormat>();
280284
psMonthly.RetentionScheduleDaily = GetPSLTRDailyRetentionFormat(serviceClientMonthly.RetentionScheduleDaily);
@@ -283,7 +287,8 @@ private static MonthlyRetentionSchedule GetPSLTRMonthlySchedule(ServiceClientMod
283287
return psMonthly;
284288
}
285289

286-
private static YearlyRetentionSchedule GetPSLTRYearlySchedule(ServiceClientModel.YearlyRetentionSchedule serviceClientYearly)
290+
private static YearlyRetentionSchedule GetPSLTRYearlySchedule(ServiceClientModel.YearlyRetentionSchedule serviceClientYearly,
291+
string timeZone)
287292
{
288293
if (serviceClientYearly == null)
289294
{
@@ -293,7 +298,7 @@ private static YearlyRetentionSchedule GetPSLTRYearlySchedule(ServiceClientModel
293298
YearlyRetentionSchedule psYearly = new YearlyRetentionSchedule();
294299

295300
psYearly.DurationCountInYears = GetRetentionDurationInYears(serviceClientYearly.RetentionDuration);
296-
psYearly.RetentionTimes = ParseDateTimesToUTC(serviceClientYearly.RetentionTimes);
301+
psYearly.RetentionTimes = ParseDateTimesToUTC(serviceClientYearly.RetentionTimes, timeZone);
297302
psYearly.RetentionScheduleFormatType =
298303
serviceClientYearly.RetentionScheduleFormatType.ToEnum<RetentionScheduleFormat>();
299304
psYearly.RetentionScheduleDaily = GetPSLTRDailyRetentionFormat(serviceClientYearly.RetentionScheduleDaily);
@@ -378,10 +383,9 @@ public static ServiceClientModel.SimpleRetentionPolicy
378383
ServiceClientModel.SimpleRetentionPolicy simpleRetPolicy =
379384
new ServiceClientModel.SimpleRetentionPolicy();
380385

381-
string durationType = psRetPolicy.RetentionDurationType.ToString();
382386
simpleRetPolicy.RetentionDuration = new ServiceClientModel.RetentionDuration();
383387
simpleRetPolicy.RetentionDuration.DurationType =
384-
durationType.ToEnum<ServiceClientModel.RetentionDurationType>();
388+
ServiceClientHelpers.GetServiceClientRetentionDurationType(psRetPolicy.RetentionDurationType);
385389
simpleRetPolicy.RetentionDuration.Count = psRetPolicy.RetentionCount;
386390

387391
return simpleRetPolicy;
@@ -496,8 +500,8 @@ private static ServiceClientModel.MonthlyRetentionSchedule GetServiceClientLTRMo
496500
psMonthly.RetentionTimes);
497501

498502
serviceClientMonthly.RetentionScheduleFormatType =
499-
psMonthly.RetentionScheduleFormatType
500-
.ToEnum<ServiceClientModel.RetentionScheduleFormat>();
503+
ServiceClientHelpers.GetServiceClientRetentionScheduleFormat(
504+
psMonthly.RetentionScheduleFormatType);
501505

502506
if (psMonthly.RetentionScheduleFormatType == RetentionScheduleFormat.Daily)
503507
{
@@ -529,8 +533,8 @@ private static ServiceClientModel.YearlyRetentionSchedule GetServiceClientLTRYea
529533
psYearly.RetentionTimes);
530534

531535
serviceClientYearly.RetentionScheduleFormatType =
532-
psYearly.RetentionScheduleFormatType
533-
.ToEnum<ServiceClientModel.RetentionScheduleFormat>();
536+
ServiceClientHelpers.GetServiceClientRetentionScheduleFormat(
537+
psYearly.RetentionScheduleFormatType);
534538

535539
if (psYearly.RetentionScheduleFormatType == RetentionScheduleFormat.Daily)
536540
{

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Helpers/Conversions/SchedulePolicyConversions.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public partial class PolicyHelpers
3131
/// Helper function to convert ps simple schedule policy from service response.
3232
/// </summary>
3333
public static SimpleSchedulePolicy GetPSSimpleSchedulePolicy(
34-
ServiceClientModel.SimpleSchedulePolicy serviceClientPolicy)
34+
ServiceClientModel.SimpleSchedulePolicy serviceClientPolicy, string timeZone)
3535
{
3636
if (serviceClientPolicy == null)
3737
{
@@ -46,7 +46,7 @@ public static SimpleSchedulePolicy GetPSSimpleSchedulePolicy(
4646
psPolicy.ScheduleRunFrequency =
4747
(ScheduleRunType)Enum.Parse(
4848
typeof(ScheduleRunType), serviceClientPolicy.ScheduleRunFrequency.ToString());
49-
psPolicy.ScheduleRunTimes = ParseDateTimesToUTC(serviceClientPolicy.ScheduleRunTimes);
49+
psPolicy.ScheduleRunTimes = ParseDateTimesToUTC(serviceClientPolicy.ScheduleRunTimes, timeZone);
5050

5151
// safe side validation
5252
psPolicy.Validate();
@@ -61,7 +61,7 @@ public static SimpleSchedulePolicy GetPSSimpleSchedulePolicy(
6161
// <summary>
6262
/// Helper function to parse utc time from local time.
6363
/// </summary>
64-
public static List<DateTime> ParseDateTimesToUTC(IList<DateTime?> localTimes)
64+
public static List<DateTime> ParseDateTimesToUTC(IList<DateTime?> localTimes, string timeZone)
6565
{
6666
if (localTimes == null || localTimes.Count == 0)
6767
{
@@ -78,9 +78,11 @@ public static List<DateTime> ParseDateTimesToUTC(IList<DateTime?> localTimes)
7878
throw new ArgumentNullException("Policy date time object is null");
7979
}
8080
temp = localTime;
81-
if (localTime.Kind != DateTimeKind.Utc)
81+
if (!string.IsNullOrEmpty(timeZone))
8282
{
83-
temp = localTime.ToUniversalTime();
83+
TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(timeZone);
84+
temp = DateTime.SpecifyKind(temp, DateTimeKind.Unspecified);
85+
temp = TimeZoneInfo.ConvertTimeToUtc(temp, timeZoneInfo);
8486
}
8587
utcTimes.Add(temp);
8688
}
@@ -101,7 +103,8 @@ public static ServiceClientModel.SimpleSchedulePolicy GetServiceClientSimpleSche
101103

102104
ServiceClientModel.SimpleSchedulePolicy serviceClientPolicy = new ServiceClientModel.SimpleSchedulePolicy();
103105
serviceClientPolicy.ScheduleRunFrequency =
104-
psPolicy.ScheduleRunFrequency.ToEnum<ServiceClientModel.ScheduleRunType>();
106+
ServiceClientHelpers.GetServiceClientScheduleRunType(
107+
psPolicy.ScheduleRunFrequency);
105108

106109
if (psPolicy.ScheduleRunFrequency == ScheduleRunType.Weekly)
107110
{

0 commit comments

Comments
 (0)