forked from Azure/azure-powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Synapse] - refine restore sqlpool (Azure#13888)
* Save current status * Redesign restore-azsynapsesqlpool * Update help doc * Update changelog * Remove unused comments * Add Restore-AzSynapseSqlPool to BreakingChangeIssues.csv Co-authored-by: Dongwei Wang <[email protected]>
- Loading branch information
Showing
18 changed files
with
17,379 additions
and
5,571 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/Synapse/Synapse.Test/ScenarioTests/SqlPoolBackupTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using Microsoft.Azure.ServiceManagement.Common.Models; | ||
using Microsoft.WindowsAzure.Commands.ScenarioTest; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Xunit; | ||
|
||
namespace Microsoft.Azure.Commands.Synapse.Test.ScenarioTests | ||
{ | ||
public class SqlPoolBackupTests: SynapseTestBase | ||
{ | ||
public XunitTracingInterceptor _logger; | ||
|
||
public SqlPoolBackupTests(Xunit.Abstractions.ITestOutputHelper output) | ||
{ | ||
_logger = new XunitTracingInterceptor(output); | ||
XunitTracingInterceptor.AddToContext(_logger); | ||
} | ||
|
||
[Fact] | ||
[Trait(Category.AcceptanceType, Category.CheckIn)] | ||
public void TestSqlPoolRestorePoint(){ | ||
NewInstance.RunPsTest( | ||
_logger, | ||
"Test-SqlPoolRestorePoint"); | ||
} | ||
|
||
[Fact] | ||
[Trait(Category.AcceptanceType, Category.CheckIn)] | ||
public void TestRestoreFromRestorePoint() | ||
{ | ||
NewInstance.RunPsTest( | ||
_logger, | ||
"Test-RestoreFromRestorePoint"); | ||
} | ||
|
||
[Fact(Skip = "Currently the test case cannot pass due to some backend issues.")] | ||
[Trait(Category.AcceptanceType, Category.CheckIn)] | ||
public void TestRestoreFromBackup(){ | ||
NewInstance.RunPsTest( | ||
_logger, | ||
"Test-RestoreFromBackup"); | ||
} | ||
} | ||
} |
219 changes: 219 additions & 0 deletions
219
src/Synapse/Synapse.Test/ScenarioTests/SqlPoolBackupTests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
# ---------------------------------------------------------------------------------- | ||
# | ||
# Copyright Microsoft Corporation | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ---------------------------------------------------------------------------------- | ||
|
||
<# | ||
.SYNOPSIS | ||
Tests for getting restore points from SQL pools | ||
#> | ||
function Test-SqlPoolRestorePoint | ||
{ | ||
# Setup | ||
$testSuffix = getAssetName | ||
Create-SqlPoolBackupTestEnvironment $testSuffix | ||
$params = Get-SqlPoolBackupTestEnvironmentParameters $testSuffix | ||
|
||
try | ||
{ | ||
# Get restore points | ||
$restorePoints = Get-AzSynapseSqlPoolRestorePoint -ResourceGroupName $params.rgname -WorkspaceName $params.workspaceName -Name $params.sqlPoolName | ||
|
||
# Create a new restore point | ||
$restorePointLabelToSet = 'ContosoRestorePoint' | ||
New-AzSynapseSqlPoolRestorePoint -ResourceGroupName $params.rgname -WorkspaceName $params.workspaceName -Name $params.sqlPoolName -RestorePointLabel $restorePointLabelToSet | ||
|
||
# Get restore points and compare with what we sent | ||
$restorePoints = Get-AzSynapseSqlPoolRestorePoint -ResourceGroupName $params.rgname -WorkspaceName $params.workspaceName -Name $params.sqlPoolName | ||
|
||
Assert-AreEqual 1 $restorePoints.Count | ||
Assert-AreEqual $restorePointLabelToSet $restorePoints[0].RestorePointLabel | ||
Assert-AreEqual 'DISCRETE' $restorePoints[0].RestorePointType | ||
Assert-Null $restorePoints[0].EarliestRestoreDate | ||
Assert-NotNull $restorePoints[0].RestorePointCreationDate | ||
|
||
# Remove restore point | ||
Remove-AzSynapseSqlPoolRestorePoint -ResourceGroupName $params.rgname -WorkspaceName $params.workspaceName -Name $params.sqlPoolName ` | ||
-RestorePointCreationDate $restorePoints[0].RestorePointCreationDate -Force | ||
|
||
# Get restore points | ||
$restorePoints = Get-AzSynapseSqlPoolRestorePoint -ResourceGroupName $params.rgname -WorkspaceName $params.workspaceName -Name $params.sqlPoolName | ||
|
||
# Check the SQL pool doesn't have any restore point | ||
Assert-AreEqual 0 $restorePoints.Count | ||
|
||
# Remove the system restore point | ||
$restorePointCannotBeDeletedErrorMessage = "Cannot delete system restore point" | ||
Assert-ThrowsContains -script { Remove-AzSynapseSqlPoolRestorePoint -ResourceGroupName $params.rgname -WorkspaceName $params.workspaceName -Name $params.sqlPoolName ` | ||
-RestorePointCreationDate $restorePoints[0].RestorePointCreationDate -Force } -message $restorePointCannotBeDeletedErrorMessage | ||
|
||
# piping scenario | ||
$pool = Get-AzSynapseSqlPool -ResourceGroupName $params.rgname -WorkspaceName $params.workspaceName -Name $params.sqlPoolName | ||
|
||
# Create a restore point | ||
$pool | New-AzSynapseSqlPoolRestorePoint -RestorePointLabel $restorePointLabelToSet | ||
|
||
# Get restore points and compare with what we sent | ||
$restorePoints = $pool | Get-AzSynapseSqlPoolRestorePoint | ||
Assert-AreEqual 1 $restorePoints.Count | ||
Assert-AreEqual $restorePointLabelToSet $restorePoints[0].RestorePointLabel | ||
Assert-AreEqual 'DISCRETE' $restorePoints[0].RestorePointType | ||
Assert-Null $restorePoints[0].EarliestRestoreDate | ||
Assert-NotNull $restorePoints[0].RestorePointCreationDate | ||
|
||
# Remove restore point | ||
$pool | Remove-AzSynapseSqlPoolRestorePoint -RestorePointCreationDate $restorePoints[0].RestorePointCreationDate -Force | ||
|
||
# Get restore points | ||
$restorePoints = $pool | Get-AzSynapseSqlPoolRestorePoint | ||
|
||
# Check the SQL pool only has one system restore point | ||
Assert-AreEqual 0 $restorePoints.Count | ||
|
||
# Create a restore point | ||
$pool | New-AzSynapseSqlPoolRestorePoint -RestorePointLabel $restorePointLabelToSet | ||
|
||
# Get restore points and compare with what we sent | ||
$restorePoints = $pool | Get-AzSynapseSqlPoolRestorePoint | ||
Assert-AreEqual 1 $restorePoints.Count | ||
Assert-AreEqual $restorePointLabelToSet $restorePoints[0].RestorePointLabel | ||
Assert-AreEqual 'DISCRETE' $restorePoints[0].RestorePointType | ||
Assert-Null $restorePoints[0].EarliestRestoreDate | ||
Assert-NotNull $restorePoints[0].RestorePointCreationDate | ||
|
||
$restorePoints[0] | Remove-AzSynapseSqlPoolRestorePoint -Force | ||
|
||
# Get restore points | ||
$restorePoints = $pool | Get-AzSynapseSqlPoolRestorePoint | ||
|
||
# Check the SQL pool only has one system restore point | ||
Assert-AreEqual 0 $restorePoints.Count | ||
} | ||
finally | ||
{ | ||
# Cleanup | ||
Remove-SqlPoolBackupTestEnvironment $testSuffix | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Tests for restoring from restore point | ||
#> | ||
function Test-RestoreFromRestorePoint | ||
{ | ||
# Setup | ||
$testSuffix = getAssetName | ||
Create-SqlPoolBackupTestEnvironment $testSuffix | ||
$params = Get-SqlPoolBackupTestEnvironmentParameters $testSuffix | ||
|
||
try | ||
{ | ||
# Create a new restore point | ||
$restorePointLabelToSet = 'ContosoRestorePoint' | ||
$restorePoint = New-AzSynapseSqlPoolRestorePoint -ResourceGroupName $params.rgname -WorkspaceName $params.workspaceName -Name $params.sqlPoolName -RestorePointLabel $restorePointLabelToSet | ||
|
||
# Transform Synapse SQL pool resource ID to SQL database ID because | ||
# currently the command only accepts the SQL databse ID | ||
$pool = Get-AzSynapseSqlPool -ResourceGroupName $params.rgname -WorkspaceName $params.workspaceName -Name $params.sqlPoolName | ||
$databaseId = $pool.Id -replace "Microsoft.Synapse", "Microsoft.Sql" ` | ||
-replace "workspaces", "servers" ` | ||
-replace "sqlPools", "databases" | ||
|
||
# Restore to same workspace with source SQL database | ||
$restoredPool = Restore-AzSynapseSqlPool -FromRestorePoint -RestorePoint $restorePoint.RestorePointCreationDate -TargetSqlPoolName $params.restoredSqlPoolName -ResourceGroupName $params.rgname ` | ||
-WorkspaceName $params.workspaceName -ResourceId $databaseId -PerformanceLevel $params.perfLevel | ||
|
||
Assert-AreEqual $params.rgname $restoredPool.ResourceGroupName | ||
Assert-AreEqual $params.workspaceName $restoredPool.WorkspaceName | ||
Assert-AreEqual $params.restoredSqlPoolName $restoredPool.SqlPoolName | ||
} | ||
finally | ||
{ | ||
# Cleanup | ||
Remove-SqlPoolBackupTestEnvironment $testSuffix | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Tests for restoring from backup | ||
#> | ||
function Test-RestoreFromBackup | ||
{ | ||
# Setup | ||
$testSuffix = getAssetName | ||
Create-SqlPoolBackupTestEnvironment $testSuffix | ||
$params = Get-SqlPoolBackupTestEnvironmentParameters $testSuffix | ||
|
||
try | ||
{ | ||
# Transform Synapse SQL pool resource ID to SQL database ID because | ||
# currently the command only accepts the SQL databse ID | ||
$pool = Get-AzSynapseSqlPool -ResourceGroupName $params.rgname -WorkspaceName $params.workspaceName -Name $params.sqlPoolName | ||
$databaseId = $pool.Id -replace "Microsoft.Synapse", "Microsoft.Sql" ` | ||
-replace "workspaces", "servers" ` | ||
-replace "sqlPools", "databases" | ||
|
||
# Restore to same workspace with source SQL database | ||
$restoredPool = Restore-AzSynapseSqlPool -FromBackup -TargetSqlPoolName $params.restoredSqlPoolName -ResourceGroupName $params.rgname ` | ||
-WorkspaceName $params.workspaceName -ResourceId $databaseId | ||
|
||
Assert-AreEqual $params.rgname $restoredPool.ResourceGroupName | ||
Assert-AreEqual $params.workspaceName $restoredPool.WorkspaceName | ||
Assert-AreEqual $params.restoredSqlPoolName $restoredPool.SqlPoolName | ||
} | ||
finally | ||
{ | ||
# Cleanup | ||
Remove-SqlPoolBackupTestEnvironment $testSuffix | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Creates the test environment needed to perform the tests | ||
#> | ||
function Create-SqlPoolBackupTestEnvironment ($testSuffix) | ||
{ | ||
$params = Get-SqlPoolBackupTestEnvironmentParameters $testSuffix | ||
Create-TestEnvironmentWithParams $params $params.location | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Gets the values of the parameters used at the tests | ||
#> | ||
function Get-SqlPoolBackupTestEnvironmentParameters ($testSuffix) | ||
{ | ||
return @{ rgname = "sql-bk-cmdlet-test-rg" +$testSuffix; | ||
workspaceName = "sqlbkws" +$testSuffix; | ||
sqlPoolName = "sqlbkpool" + $testSuffix; | ||
storageAccountName = "sqlbkstorage" + $testSuffix; | ||
fileSystemName = "sqlbkcmdletfs" + $testSuffix; | ||
loginName = "testlogin"; | ||
pwd = "testp@ssMakingIt1007Longer"; | ||
perfLevel = 'DW200c'; | ||
location = "westcentralus"; | ||
restoredSqlPoolName = "dwrestore" + $testSuffix; | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Removes the test environment that was needed to perform the tests | ||
#> | ||
function Remove-SqlPoolBackupTestEnvironment ($testSuffix) | ||
{ | ||
$params = Get-SqlPoolBackupTestEnvironmentParameters $testSuffix | ||
Remove-AzResourceGroup -Name $params.rgname -Force | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.