Skip to content

Commit 1876ca2

Browse files
authored
Merge pull request #11017 from MabOneSdk/users/sarath/restoreas-files
[RecoveryServices.Backup] Restore-As-Files support for Mercury
2 parents 6b4f4a5 + 136ffb0 commit 1876ca2

File tree

60 files changed

+529577
-4528460
lines changed

Some content is hidden

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

60 files changed

+529577
-4528460
lines changed

src/RecoveryServices/RecoveryServices.Backup.Helpers/RecoveryServices.Backup.Helpers.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.0.0-preview" />
15+
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.0.1-preview" />
1616
<PackageReference Include="TimeZoneConverter" Version="3.0.0" />
1717
</ItemGroup>
1818

src/RecoveryServices/RecoveryServices.Backup.Models/AzureVmWorkloadModels/AzureWorkloadRecoveryConfig.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ public class AzureWorkloadRecoveryConfig : RecoveryConfigBase
5555

5656
public string ContainerId { get; set; }
5757

58+
/// <summary>
59+
/// Full RP on which log backups will be applied
60+
/// </summary>
61+
public RecoveryPointBase FullRP { get; set; }
62+
63+
5864
public AzureWorkloadRecoveryConfig(string targetServer, string targetInstance, string restoreRequestType,
5965
RecoveryPointBase recoveryPoint, DateTime pointInTime)
6066
: base(restoreRequestType, recoveryPoint, pointInTime)

src/RecoveryServices/RecoveryServices.Backup.Models/BaseObjects.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ public class RecoveryConfigBase
492492
/// <summary>
493493
/// Original WL Restore, Alternate WL restore, Alternate WL restore to diff item.
494494
/// </summary>
495-
public string RestoreRequestType { get; }
495+
public string RestoreRequestType { get; set; }
496496

497497
/// <summary>
498498
/// Recovery point for full/differential backup.
@@ -504,6 +504,16 @@ public class RecoveryConfigBase
504504
/// </summary>
505505
public DateTime PointInTime { get; }
506506

507+
/// <summary>
508+
/// Recovery Mode
509+
/// </summary>
510+
public string RecoveryMode { get; set; }
511+
512+
/// <summary>
513+
/// File path for Restore as Files
514+
/// </summary>
515+
public string FilePath { get; set; }
516+
507517
public RecoveryConfigBase(string restoreRequestType, RecoveryPointBase recoveryPoint, DateTime pointInTime)
508518
{
509519
RestoreRequestType = restoreRequestType;

src/RecoveryServices/RecoveryServices.Backup.Models/Properties/Resources.Designer.cs

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/RecoveryServices/RecoveryServices.Backup.Models/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,4 +583,7 @@ Please contact Microsoft for further assistance.</value>
583583
<data name="FriendlyNamePassedWarning" xml:space="preserve">
584584
<value>A friendly name might return multiple items since it is not unique. To get a unique item, please use the -name parameter. Pass the value displayed under the name column when displayed as a table or use the name field in the PS object</value>
585585
</data>
586+
<data name="TargetContainerRequiredException" xml:space="preserve">
587+
<value>Target Container parameter is required for this operation.</value>
588+
</data>
586589
</root>

src/RecoveryServices/RecoveryServices.Backup.Models/RecoveryServices.Backup.Models.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.0.0-preview" />
15+
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.0.1-preview" />
1616
</ItemGroup>
1717

1818
</Project>

src/RecoveryServices/RecoveryServices.Backup.Providers/Providers/AzureWorkloadPsBackupProvider.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
377377
(AzureWorkloadRecoveryConfig)ProviderData[RestoreWLBackupItemParams.WLRecoveryConfig];
378378
RestoreRequestResource triggerRestoreRequest = new RestoreRequestResource();
379379

380-
if (wLRecoveryConfig.RecoveryPoint.ContainerName != null)
380+
if (wLRecoveryConfig.RecoveryPoint.ContainerName != null && wLRecoveryConfig.FullRP == null)
381381
{
382382
AzureWorkloadSQLRestoreRequest azureWorkloadSQLRestoreRequest =
383383
new AzureWorkloadSQLRestoreRequest();
@@ -401,6 +401,17 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
401401
};
402402
azureWorkloadSQLRestoreRequest.AlternateDirectoryPaths = wLRecoveryConfig.targetPhysicalPath;
403403
}
404+
if (wLRecoveryConfig.RecoveryMode == "FileRecovery")
405+
{
406+
azureWorkloadSQLRestoreRequest.RecoveryMode = "FileRecovery";
407+
azureWorkloadSQLRestoreRequest.TargetInfo = new TargetRestoreInfo()
408+
{
409+
OverwriteOption = string.Compare(wLRecoveryConfig.OverwriteWLIfpresent, "No") == 0 ?
410+
OverwriteOptions.FailOnConflict : OverwriteOptions.Overwrite,
411+
ContainerId = wLRecoveryConfig.ContainerId,
412+
TargetDirectoryForFileRestore = wLRecoveryConfig.FilePath
413+
};
414+
}
404415
triggerRestoreRequest.Properties = azureWorkloadSQLRestoreRequest;
405416
}
406417
else
@@ -427,6 +438,19 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
427438
};
428439
azureWorkloadSQLPointInTimeRestoreRequest.AlternateDirectoryPaths = wLRecoveryConfig.targetPhysicalPath;
429440
}
441+
442+
if (wLRecoveryConfig.RecoveryMode == "FileRecovery")
443+
{
444+
azureWorkloadSQLPointInTimeRestoreRequest.RecoveryMode = "FileRecovery";
445+
azureWorkloadSQLPointInTimeRestoreRequest.TargetInfo = new TargetRestoreInfo()
446+
{
447+
OverwriteOption = string.Compare(wLRecoveryConfig.OverwriteWLIfpresent, "No") == 0 ?
448+
OverwriteOptions.FailOnConflict : OverwriteOptions.Overwrite,
449+
ContainerId = wLRecoveryConfig.ContainerId,
450+
TargetDirectoryForFileRestore = wLRecoveryConfig.FilePath
451+
};
452+
}
453+
430454
azureWorkloadSQLPointInTimeRestoreRequest.PointInTime = wLRecoveryConfig.PointInTime;
431455
triggerRestoreRequest.Properties = azureWorkloadSQLPointInTimeRestoreRequest;
432456
}

src/RecoveryServices/RecoveryServices.Backup.Providers/RecoveryServices.Backup.Providers.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.0.0-preview" />
15+
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.0.1-preview" />
1616
</ItemGroup>
1717

1818
<ItemGroup>

src/RecoveryServices/RecoveryServices.Backup.ServiceClientAdapter/RecoveryServices.Backup.ServiceClientAdapter.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<ItemGroup>
1515
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices" Version="4.2.1-preview" />
16-
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.0.0-preview" />
16+
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.0.1-preview" />
1717
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.4.1" />
1818
</ItemGroup>
1919

src/RecoveryServices/RecoveryServices.Backup.Test/RecoveryServices.Backup.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<PackageReference Include="Microsoft.Azure.Management.Compute" Version="31.0.0" />
1515
<PackageReference Include="Microsoft.Azure.Management.Network" Version="19.18.0-preview" />
1616
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices" Version="4.2.1-preview" />
17-
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.0.0-preview" />
17+
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.0.1-preview" />
1818
</ItemGroup>
1919

2020
<ItemGroup>

src/RecoveryServices/RecoveryServices.Backup.Test/ScenarioTests/AzureWorkload/ItemTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,14 @@ public void TestAzureVmWorkloadFullRestoreWithFiles()
103103
TestController.NewInstance.RunPsTest(
104104
_logger, PsBackupProviderTypes.AzureWorkload, "Test-AzureVmWorkloadFullRestoreWithFiles");
105105
}
106+
107+
[Fact]
108+
[Trait(Category.AcceptanceType, Category.CheckIn)]
109+
[Trait(TestConstants.Workload, TestConstants.AzureVmWorkload)]
110+
public void TestAzureVmWorkloadRestoreAsFiles()
111+
{
112+
TestController.NewInstance.RunPsTest(
113+
_logger, PsBackupProviderTypes.AzureWorkload, "Test-AzureVmWorkloadRestoreAsFiles");
114+
}
106115
}
107116
}

src/RecoveryServices/RecoveryServices.Backup.Test/ScenarioTests/AzureWorkload/ItemTests.ps1

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ $containerName = "psbvtsqlvm"
1616
$resourceGroupName = "pstestwlRG1bca8"
1717
$vaultName = "pstestwlRSV1bca8"
1818
$resourceId = "/subscriptions/38304e13-357e-405e-9e9a-220351dcce8c/resourceGroups/pscloudtestrg/providers/Microsoft.Compute/virtualMachines/psbvtsqlvm"
19+
$filepath = "C:\"
20+
$restoreAsFilesVault = "iaasvmsqlworkloadexistingvault1"
1921
$resourceIdForFileDB = $resourceId
2022
$policyName = "HourlyLogBackup"
2123
$instanceName = "sqlinstance;mssqlserver"
@@ -602,4 +604,56 @@ function Test-AzureVmWorkloadFullRestoreWithFiles
602604
{
603605
Cleanup-Vault $vault $item $container
604606
}
607+
}
608+
609+
function Test-AzureVmWorkloadRestoreAsFiles
610+
{
611+
$vault = Get-AzRecoveryServicesVault -Name $restoreAsFilesVault
612+
613+
$container = Get-AzRecoveryServicesBackupContainer `
614+
-VaultId $vault.ID `
615+
-ContainerType "AzureVMAppContainer";
616+
617+
$item = Get-AzRecoveryServicesBackupItem `
618+
-VaultId $vault.ID `
619+
-BackupManagementType "AzureWorkload" `
620+
-WorkloadType "MSSQL";
621+
622+
$endtime = get-date -Year 2020 -Month 1 -Day 31 -Minute 35 -Hour 23 -Second 15
623+
$endtime = $endtime.ToUniversalTime()
624+
$starttime = $endtime.AddDays(-30)
625+
$starttime = $starttime.ToUniversalTime()
626+
627+
$rp = Get-AzRecoveryServicesBackupRecoveryPoint -VaultId $vault.ID -Item $item -StartDate $starttime -EndDate $endtime
628+
$time = get-date -Year 2020 -Month 1 -Day 30 -Minute 5
629+
$config = Get-AzRecoveryServicesBackupWorkloadRecoveryConfig `
630+
-VaultId $vault.ID -PointInTime $time -Item $item -RestoreAsFiles `
631+
-FilePath $filepath -TargetContainer $container -FromFull $rp[3];
632+
633+
$restorejob1 = Restore-AzRecoveryServicesBackupItem `
634+
-VaultId $vault.ID `
635+
-WLRecoveryConfig $config | Wait-AzureRmRecoveryServicesBackupJob -VaultId $vault.ID;
636+
637+
Assert-True { $restorejob1.Status -eq "Completed" }
638+
639+
$config = Get-AzRecoveryServicesBackupWorkloadRecoveryConfig `
640+
-VaultId $vault.ID -RecoveryPoint $rp[0] -Item $item -RestoreAsFiles `
641+
-FilePath $filepath -TargetContainer $container;
642+
643+
$restorejob2 = Restore-AzRecoveryServicesBackupItem `
644+
-VaultId $vault.ID `
645+
-WLRecoveryConfig $config | Wait-AzureRmRecoveryServicesBackupJob -VaultId $vault.ID
646+
647+
Assert-True { $restorejob2.Status -eq "Completed" }
648+
649+
$config = Get-AzRecoveryServicesBackupWorkloadRecoveryConfig `
650+
-VaultId $vault.ID -PointInTime $time -Item $item -RestoreAsFiles `
651+
-FilePath $filepath -TargetContainer $container;
652+
653+
$restorejob3 = Restore-AzRecoveryServicesBackupItem `
654+
-VaultId $vault.ID `
655+
-WLRecoveryConfig $config | Wait-AzureRmRecoveryServicesBackupJob -VaultId $vault.ID
656+
657+
Assert-True { $restorejob3.Status -eq "Completed" }
658+
605659
}

0 commit comments

Comments
 (0)