|
637 | 637 | sql-files="<folder-name>\*.sql" /> |
638 | 638 | ``` |
639 | 639 |
|
| 640 | +## Execute SSMA console in parallel |
| 641 | + |
| 642 | +The SSMA console utility can be executed in parallel through scripting, by specifying the database name and corresponding folder path as input parameters. In the following example, the databases `SAMPLE1`, `SAMPLE2`, and `SAMPLE3`, with their respective folder paths, are supplied as input to the script. |
| 643 | + |
| 644 | +```txt |
| 645 | +SAMPLE1,C:\folder path\SSMA Project1 |
| 646 | +SAMPLE2,C:\folder path\SSMA Project2 |
| 647 | +SAMPLE3,C:\folder path\SSMA Project3 |
| 648 | +``` |
| 649 | + |
| 650 | +The following sample PowerShell script enables parallel execution of the SSMA console. |
| 651 | + |
| 652 | +```powershell |
| 653 | +$baseFolder = "C:\folder path\folder1" |
| 654 | +$ssmaExe = "C:\folder path\SSMAforDb2Console.exe" |
| 655 | +$databaselistPath = Join-Path $baseFolder "Databaselist.txt" |
| 656 | +$conversionXmlTemplate = Join-Path $baseFolder "ConversionAndDataMigrationSample.xml" |
| 657 | +$variableXmlTemplate = Join-Path $baseFolder "VariableValueFileSample.xml" |
| 658 | +
|
| 659 | +# Read all entries |
| 660 | +$entries = Get-Content $databaselistPath | Where-Object { $_.Trim() -ne "" } |
| 661 | +
|
| 662 | +# Prepare the entries |
| 663 | +$preparedEntries = foreach ($entry in $entries) { |
| 664 | + $parts = $entry -split "," |
| 665 | + $dbName = $parts[0].Trim() |
| 666 | + $workingFolder = $parts[1].Trim() |
| 667 | + if ($dbNameCounts.ContainsKey($dbName)) { |
| 668 | + $dbNameCounts[$dbName]++ |
| 669 | + $suffix = "_{0:D2}" -f $dbNameCounts[$dbName] |
| 670 | + $fileDbName = "$dbName$suffix" |
| 671 | + } |
| 672 | + else { |
| 673 | + $dbNameCounts[$dbName] = 0 |
| 674 | + $fileDbName = $dbName |
| 675 | + } |
| 676 | + [PSCustomObject]@{ |
| 677 | + DbName = $dbName |
| 678 | + WorkingFolder = $workingFolder |
| 679 | + FileDbName = $fileDbName |
| 680 | + } |
| 681 | +} |
| 682 | +
|
| 683 | +# Run in parallel |
| 684 | +$preparedEntries | ForEach-Object -Parallel { |
| 685 | + $dbName = $_.DbName |
| 686 | + $workingFolder = $_.WorkingFolder |
| 687 | + $fileDbName = $_.FileDbName |
| 688 | +
|
| 689 | + # Update ConversionAndDataMigrationSample.xml |
| 690 | + $convTree = [xml](Get-Content $using:conversionXmlTemplate) |
| 691 | + $convTree.SelectNodes("//initial-catalog") | ForEach-Object { $_.SetAttribute("value", $dbName) } |
| 692 | + $conversionXmlPath = Join-Path $using:baseFolder "ConversionAndDataMigrationSample_$fileDbName.xml" |
| 693 | + $convTree.Save($conversionXmlPath) |
| 694 | + |
| 695 | + # Update VariableValueFileSample.xml |
| 696 | + $varTree = [xml](Get-Content $using:variableXmlTemplate) |
| 697 | + $nodes = $varTree.SelectNodes('//variable[@name="$WorkingFolder$"]') |
| 698 | + if ($nodes.Count -eq 0) { |
| 699 | + Write-Host "No variable node found for `$WorkingFolder$" |
| 700 | + } |
| 701 | + else { |
| 702 | + $nodes | ForEach-Object { $_.value = $workingFolder } |
| 703 | + } |
| 704 | + $nodes2 = $varTree.SelectNodes('//variable[@name="$Db2InitialCatalog$"]') |
| 705 | + if ($nodes2.Count -eq 0) { |
| 706 | + Write-Host "No variable node found for `$Db2InitialCatalog$" |
| 707 | + } |
| 708 | + else { |
| 709 | + $nodes2 | ForEach-Object { $_.value = $dbName } |
| 710 | + } |
| 711 | + $variableXmlPath = Join-Path $using:baseFolder "VariableValueFileSample_$fileDbName.xml" |
| 712 | + $varTree.Save($variableXmlPath) |
| 713 | +
|
| 714 | + # Prepare output/error file paths |
| 715 | + $outputFile = Join-Path $using:baseFolder "ssma_output_$fileDbName.txt" |
| 716 | + $errorFile = Join-Path $using:baseFolder "ssma_error_$fileDbName.txt" |
| 717 | +
|
| 718 | + # Prepare argument list |
| 719 | + $arguments = "-s `"$conversionXmlPath`" -v `"$variableXmlPath`"" |
| 720 | +
|
| 721 | + # Run SSMA console |
| 722 | + Start-Process -FilePath $using:ssmaExe -ArgumentList $arguments -RedirectStandardOutput $outputFile -RedirectStandardError $errorFile -Wait |
| 723 | + Write-Host "Executed command: `"$using:ssmaExe`" $arguments" |
| 724 | +} |
| 725 | +``` |
| 726 | + |
640 | 727 | ## Related content |
641 | 728 |
|
642 | 729 | - [Command line options in SSMA console (Db2ToSQL)](command-line-options-in-ssma-console-db2tosql.md) |
|
0 commit comments