Skip to content

Commit

Permalink
Migrate DataMigration from generation to main (Azure#19608)
Browse files Browse the repository at this point in the history
* Move DataMigration to main

* update docs

Co-authored-by: wyunchi-ms <yunwang@microsoft.com>
  • Loading branch information
azure-powershell-bot and wyunchi-ms authored Sep 28, 2022
1 parent 0619ab7 commit 662d0ec
Show file tree
Hide file tree
Showing 195 changed files with 2,131 additions and 927 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@

# ----------------------------------------------------------------------------------
#
# 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
Migrate logins from the source Sql Servers to the target Azure Sql Servers.
.Description
Migrate logins from the source Sql Servers to the target Azure Sql Servers.
#>


function New-AzDataMigrationLoginsMigration
{
[OutputType([System.Boolean])]
[CmdletBinding(PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')]
[Microsoft.Azure.PowerShell.Cmdlets.DataMigration.Description('Migrate logins from the source Sql Servers to the target Azure Sql Servers.')]

param(
[Parameter(ParameterSetName='CommandLine', Mandatory, HelpMessage='Required. Connection string(s) for the source SQL instance(s), using the formal connection string format.')]
[System.String[]]
${SourceSqlConnectionString},


[Parameter(ParameterSetName='CommandLine', Mandatory, HelpMessage='Required. Connection string(s) for the target SQL instance(s), using the formal connection string format.')]
[System.String]
${TargetSqlConnectionString},

[Parameter(ParameterSetName='CommandLine', HelpMessage='Optional. Location of CSV file of logins. Use only one parameter between this and listOfLogin.')]
[System.String]
${CSVFilePath},

[Parameter(ParameterSetName='CommandLine', HelpMessage='Optional. List of logins in string format. If large number of logins need to be migrated, use CSV file option.')]
[System.String[]]
${ListOfLogin},

[Parameter(ParameterSetName='CommandLine', HelpMessage='Optional. Default: %LocalAppData%/Microsoft/SqlLoginMigrations) Folder where logs will be written.')]
[System.String]
${OutputFolder},

[Parameter(ParameterSetName='CommandLine', HelpMessage='Optional. Required if Windows logins are included in the list of logins to be migrated. (Default: empty string).')]
[System.String]
${AADDomainName},

[Parameter(ParameterSetName='ConfigFile', Mandatory, HelpMessage='Path of the ConfigFile')]
[System.String]
${ConfigFilePath},

[Parameter()]
[Microsoft.Azure.PowerShell.Cmdlets.DataMigration.Category('Runtime')]
[System.Management.Automation.SwitchParameter]
# Returns true when the command succeeds
${PassThru}
)

process
{
try
{
$OSPlatform = Get-OSName

if(-Not $OSPlatform.Contains("Windows"))
{
throw "This command cannot be run in non-windows environment"
Break;
}

#Defining Default Output Path
$DefaultOutputFolder = Get-DefaultLoginMigrationsOutputFolder

#Defining Base and Exe paths
$BaseFolder = Join-Path -Path $DefaultOutputFolder -ChildPath Downloads;
$ExePath = Join-Path -Path $BaseFolder -ChildPath Logins.Console.csproj\Logins.Console.exe;

#Checking if BaseFolder Path is valid or not
if(-Not (Test-Path $BaseFolder))
{
$null = New-Item -Path $BaseFolder -ItemType "directory"
}

#Testing Whether Console App is downloaded or not
$TestExePath = Test-Path -Path $ExePath;

#Downloading and extracting LoginsMigration Zip file
if(-Not $TestExePath)
{
$ZipSource = "https://sqlloginmigration.blob.core.windows.net/app/LoginsMigration.zip";
$ZipDestination = Join-Path -Path $BaseFolder -ChildPath "LoginsMigration.zip";
Invoke-RestMethod -Uri $ZipSource -OutFile $ZipDestination;

Expand-Archive -Path $ZipDestination -DestinationPath $BaseFolder -Force;
}

#Collecting data
if(('CommandLine') -contains $PSCmdlet.ParameterSetName)
{
# The array list $splat contains all the parameters that will be passed to '.\Logins.Console.exe LoginsMigration'

$LoginsListArray = $($ListOfLogin -split " ")
[System.Collections.ArrayList] $splat = @(
'--sourceSqlConnectionString', $SourceSqlConnectionString
'--targetSqlConnectionString', $TargetSqlConnectionString
'--csvFilePath', $CSVFilePath
'--listOfLogin', $LoginsListArray
'--outputFolder', $OutputFolder
'--aadDomainName', $AADDomainName
)
# Removing the parameters for which the user did not provide any values
for($i = $splat.Count-1; $i -gt -1; $i = $i-2)
{
$currVal = $splat[$i]
if($currVal -ne "")
{
}
else {
$splat.RemoveAt($i)
$i2 = $i -1
$splat.RemoveAt($i2)

}
}
# Running LoginsMigration
& $ExePath LoginsMigration @splat
}
else
{
Test-LoginMigrationsConfigFile $PSBoundParameters.ConfigFilePath
& $ExePath --configFile $PSBoundParameters.ConfigFilePath
}

$LogFilePath = Join-Path -Path $DefaultOutputFolder -ChildPath Logs;
Write-Host "Event and Error Logs Folder Path: $LogFilePath";

if($PSBoundParameters.ContainsKey("PassThru"))
{
return $true;
}
}
catch
{
throw $_
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# ----------------------------------------------------------------------------------
#
# 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.
# ----------------------------------------------------------------------------------


# Function Definitions

function Test-LoginMigrationsConfigFile{
[Microsoft.Azure.PowerShell.Cmdlets.DataMigration.DoNotExportAttribute()]
param(
[Parameter(Mandatory=$true)]
[System.String]
$path
)

process {
if (!(Test-Path -Path $path))
{
throw "Invalid Config File path: $path"
}
}
}

function Get-DefaultLoginMigrationsOutputFolder {
[Microsoft.Azure.PowerShell.Cmdlets.DataMigration.DoNotExportAttribute()]
param(
)

process {
$OSPlatform = Get-OSName

if($OSPlatform.Contains("Linux"))
{
$DefualtPath = Join-Path -Path $env:USERPROFILE -ChildPath ".config\Microsoft\SqlLoginMigrations";

}
elseif ($OSPlatform.Contains("Darwin"))
{
$DefualtPath = Join-Path -Path $env:USERPROFILE -ChildPath "Library\Application Support\Microsoft\SqlLoginMigrations";
}
else
{
$DefualtPath = Join-Path -Path $env:LOCALAPPDATA -ChildPath "Microsoft\SqlLoginMigrations";
}

return $DefualtPath

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ Initiate cutover for in-progress online database migration to SQL Managed Instan
### [Invoke-AzDataMigrationCutoverToSqlVM](Invoke-AzDataMigrationCutoverToSqlVM.md)
Initiate cutover for in-progress online database migration to SQL VM.

### [New-AzDataMigrationLoginsMigration](New-AzDataMigrationLoginsMigration.md)
Migrate logins from the source Sql Servers to the target Azure Sql Servers.

### [New-AzDataMigrationSqlService](New-AzDataMigrationSqlService.md)
Create or Update Database Migration Service.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Collect performance data for given SQL Server instance(s)

### Example 1: Run Performance Data Collection on given SQL Server using connection string
```powershell
PS C:\> Get-AzDataMigrationPerformanceDataCollection -SqlConnectionStrings "Data Source=AALAB03-2K8.REDMOND.CORP.MICROSOFT.COM;Initial Catalog=master;Integrated Security=False;User Id=dummyUserId;Password=dummyPassword" -NumberOfIterations 2
Get-AzDataMigrationPerformanceDataCollection -SqlConnectionStrings "Data Source=AALAB03-2K8.REDMOND.CORP.MICROSOFT.COM;Initial Catalog=master;Integrated Security=False;User Id=dummyUserId;Password=dummyPassword" -NumberOfIterations 2
```

```output
Expand Down Expand Up @@ -62,7 +62,7 @@ This command runs Performance Data Collection on given SQL Server using the conn

### Example 2: Run Performance Data Collection on given SQL Server using assessment config file
```powershell
PS C:\> Get-AzDataMigrationAssessment -ConfigFilePath "C:\Users\user\document\config.json"
Get-AzDataMigrationPerformanceDataCollection -ConfigFilePath "C:\Users\user\document\config.json"
```

```output
Expand Down Expand Up @@ -92,7 +92,7 @@ This command runs Performance Data Collection on given SQL Server using the conf

### Example 3: Run Performance Data Collection on given SQL Server that stops after a specified time
```powershell
PS C:\> Get-AzDataMigrationAssessment -ConfigFilePath "C:\Users\user\document\config.json" -Time 120
Get-AzDataMigrationPerformanceDataCollection -ConfigFilePath "C:\Users\user\document\config.json" -Time 120
```

```output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Gives SKU recommendations for Azure SQL offerings

### Example 1: Run SKU Recommendation on given SQL Server using connection string
```powershell
PS C:\> Get-AzDataMigrationSkuRecommendation -DisplayResult
Get-AzDataMigrationSkuRecommendation -DisplayResult
```

```output
Expand Down Expand Up @@ -61,7 +61,7 @@ This command runs Run SKU Recommendation on given SQL Server using the connectio

### Example 2: Run Run SKU Recommendation on given SQL Server using assessment config file
```powershell
PS C:\> Get-AzDataMigrationSkuRecommendation -ConfigFilePath "C:\Users\user\document\config.json"
Get-AzDataMigrationSkuRecommendation -ConfigFilePath "C:\Users\user\document\config.json"
```

```output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Get-AzDataMigrationSqlService -ResourceGroupName "MyResourceGroup"
Location Name Type ProvisioningState IntegrationRuntimeState
-------- ---- ---- ----------------- -----------------------
eastus MySqlMigrationService1 Microsoft.DataMigration/sqlMigrationServices Succeeded
eastus2 MySqlMigrationService Microsoft.DataMigration/sqlMigrationServices Succeeded
eastus2 MySqlMigrationService Microsoft.DataMigration/sqlMigrationServices Succeeded
```

This command gets all Sql Migration Services in a given Resource Group.
Expand All @@ -78,7 +78,7 @@ Location Name Type
-------- ---- ---- ----------------- -----------------------
eastus MySqlMigrationService1 Microsoft.DataMigration/sqlMigrationServices Succeeded
eastus2 MySqlMigrationService Microsoft.DataMigration/sqlMigrationServices Succeeded
uksouth MySqlMigrationService-UK Microsoft.DataMigration/sqlMigrationServices Succeeded
uksouth MySqlMigrationService-UK Microsoft.DataMigration/sqlMigrationServices Succeeded
```

This command gets all Sql Migration Services in a given Subscription.
Expand Down Expand Up @@ -197,7 +197,7 @@ COMPLEX PARAMETER PROPERTIES
To create the parameters described below, construct a hash table containing the appropriate properties. For information on hash tables, run Get-Help about_Hash_Tables.
INPUTOBJECT <IDataMigrationIdentity>: Identity Parameter
`INPUTOBJECT <IDataMigrationIdentity>`: Identity Parameter
- `[Id <String>]`: Resource identity path
- `[ManagedInstanceName <String>]`:
- `[ResourceGroupName <String>]`: Name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Retrieve the registered Integration Runtime nodes and their monitoring data for

### Example 1: Get the registered Integration Runtime nodes and their monitoring data for a given Sql Migration Service
```powershell
Get-AzDataMigrationSqlServiceIntegrationRuntimeMetric -ResourceGroupName "MyResourceGroup" -SqlMigrationServiceName "MySqlMigrationService" | Select *
Get-AzDataMigrationSqlServiceIntegrationRuntimeMetric -ResourceGroupName "MyResourceGroup" -SqlMigrationServiceName "MySqlMigrationService" | Select-Object *
```

```output
Expand All @@ -38,7 +38,7 @@ This command gets the registered Integration Runtime nodes and their monitoring

### Example 2: Print the monitoring data for each Integration Runtime node
```powershell
$item = Get-AzDataMigrationSqlServiceIntegrationRuntimeMetric -ResourceGroupName "MyResourceGroup" -SqlMigrationService "MySqlMigrationService"
$item = Get-AzDataMigrationSqlServiceIntegrationRuntimeMetric -ResourceGroupName "MyResourceGroup" -SqlMigrationServiceName "MySqlMigrationService"
$item.Node[0]
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ COMPLEX PARAMETER PROPERTIES
To create the parameters described below, construct a hash table containing the appropriate properties. For information on hash tables, run Get-Help about_Hash_Tables.
INPUTOBJECT <IDataMigrationIdentity>: Identity Parameter
`INPUTOBJECT <IDataMigrationIdentity>`: Identity Parameter
- `[Id <String>]`: Resource identity path
- `[ManagedInstanceName <String>]`:
- `[ResourceGroupName <String>]`: Name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ COMPLEX PARAMETER PROPERTIES
To create the parameters described below, construct a hash table containing the appropriate properties. For information on hash tables, run Get-Help about_Hash_Tables.
INPUTOBJECT <IDataMigrationIdentity>: Identity Parameter
`INPUTOBJECT <IDataMigrationIdentity>`: Identity Parameter
- `[Id <String>]`: Resource identity path
- `[ManagedInstanceName <String>]`:
- `[ResourceGroupName <String>]`: Name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ COMPLEX PARAMETER PROPERTIES
To create the parameters described below, construct a hash table containing the appropriate properties. For information on hash tables, run Get-Help about_Hash_Tables.
INPUTOBJECT <IDataMigrationIdentity>: Identity Parameter
`INPUTOBJECT <IDataMigrationIdentity>`: Identity Parameter
- `[Id <String>]`: Resource identity path
- `[ManagedInstanceName <String>]`:
- `[ResourceGroupName <String>]`: Name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal.
Expand Down
Loading

0 comments on commit 662d0ec

Please sign in to comment.