Skip to content

Commit 873bcd9

Browse files
authored
Update executing-the-ssma-console-db2tosql.md
Added new section for executing SSMA console in parallel and provided the sample script for it.
1 parent 5ffc31c commit 873bcd9

1 file changed

Lines changed: 88 additions & 0 deletions

File tree

docs/ssma/db2/executing-the-ssma-console-db2tosql.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,94 @@ Or
637637
sql-files="<folder-name>\*.sql" />
638638
```
639639

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

642730
- [Command line options in SSMA console (Db2ToSQL)](command-line-options-in-ssma-console-db2tosql.md)

0 commit comments

Comments
 (0)