summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Korotkov <dkorotkov@mirantis.com>2013-03-03 01:59:06 -0800
committerDmitry Korotkov <dkorotkov@mirantis.com>2013-03-03 01:59:06 -0800
commit6ca53fd844ac4c37156183cc0772989dd822db42 (patch)
tree968292c19da0984bc331c34baa62d09201e11126
parent1903d22b1565cdf6929ee7f20f377dc31da08c1d (diff)
[KEERO-96] Written outbound mirroring endpoint initialization code.mssql
-rw-r--r--Deployment/MSSQL/SQLServerInstaller.psm1123
1 files changed, 123 insertions, 0 deletions
diff --git a/Deployment/MSSQL/SQLServerInstaller.psm1 b/Deployment/MSSQL/SQLServerInstaller.psm1
index 477e38a..99ddf73 100644
--- a/Deployment/MSSQL/SQLServerInstaller.psm1
+++ b/Deployment/MSSQL/SQLServerInstaller.psm1
@@ -2,6 +2,17 @@ Import-Module '.\OptionParser.psm1'
2Import-Module '.\SQLServerOptionParsers.psm1' 2Import-Module '.\SQLServerOptionParsers.psm1'
3 3
4function New-SQLServer { 4function New-SQLServer {
5 <#
6 .SYNOPSIS
7 Installs new MS SQL Server instance
8
9 .DESCRIPTION
10 Installs new MS SQL Server instance in unattended mode.
11
12 .PARAMETER SetupRoot
13 MS SQL Server installation files root directory. Normally it is just DVD drive name.
14 #>
15
5 param( 16 param(
6 [parameter(Mandatory = $true)] 17 [parameter(Mandatory = $true)]
7 [string]$SetupRoot 18 [string]$SetupRoot
@@ -19,6 +30,17 @@ function New-SQLServer {
19} 30}
20 31
21function Remove-SQLServer { 32function Remove-SQLServer {
33 <#
34 .SYNOPSIS
35 Uninstalls MS SQL Server instance installed with New-SQLServer cmdlet
36
37 .DESCRIPTION
38 Uninstalls MS SQL Server instance installed with New-SQLServer cmdlet in unattended mode
39
40 .PARAMETER SetupRoot
41 MS SQL Server installation files root directory. Normally it is just DVD drive name.
42 #>
43
22 param( 44 param(
23 [parameter(Mandatory = $true)] 45 [parameter(Mandatory = $true)]
24 [string]$SetupRoot 46 [string]$SetupRoot
@@ -34,5 +56,106 @@ function Remove-SQLServer {
34 throw "Installation executable exited with code $("{0:X8}" -f $ExitCode)" 56 throw "Installation executable exited with code $("{0:X8}" -f $ExitCode)"
35 } 57 }
36} 58}
59
60function Invoke-SQLText {
61 <#
62 .SYNOPSIS
63 Invokes SQL text
64
65 .DESCRIPTION
66 Invokes SQL text
67
68 .PARAMETER SQL
69 SQL Text
70
71 .PARAMETER User
72 SQL Server user name
73
74 .PARAMETER SQL
75 SQL Server user password
76 #>
77 param(
78 [parameter(Mandatory = $true)]
79 [string]$SQL,
80 [string]$User = $null,
81 [string]$Password = $null
82 )
83
84 $Binary = Get-Command "sqlcmd.exe"
85
86 $tempFile = [IO.Path]::GetTempFileName()
87 $tempFile = Get-Item $tempFile
88 Set-Content -Path $tempFile -Value $SQL
89
90 $CommandLine = @('-i', "`"$($tempFile.FullName)`"")
91 if (($User -ne $null) -and ($User -ne '')) {
92 $CommandLine = $CommandLine + '-U'
93 $CommandLine = $CommandLine + $User
94 $CommandLine = $CommandLine + '-P'
95 $CommandLine = $CommandLine + $Password
96 }
97
98 Write-Host "Executing: `"$($Binary.Path)`" $($CommandLine -join ' ')"
99 $process = [System.Diagnostics.Process]::Start($Binary, $CommandLine)
100 $process.WaitForExit()
101 $process.Refresh()
102
103 $ExitCode = $process.ExitCode
104 if ($ExitCode -ne 0) {
105 throw "SQLCMD.EXE returned with exit code $ExitCode"
106 }
107
108 Remove-Item $tempFile
109}
110
111function Initialize-MirroringEndpoint {
112 <#
113 .SYNOPSIS
114 Prepares SQL Server for database mirroring
115
116 .DESCRIPTION
117 ToDo: Describe
118 #>
119
120 param(
121 [parameter(Mandatory = $true)]
122 [String]$EncryptionPassword,
123 [parameter(Mandatory = $true)]
124 [String]$WorkDir
125 )
126
127 $Folder = Get-Item $WorkDir
128
129 $H = $Env:COMPUTERNAME -replace '[^A-Za-z0-9_]', ''
130
131 $CreateMasteeKey = "USE master;
132 CREATE MASTER KEY ENCRYPTION BY PASSWORD = '$EncryptionPassword';
133 GO
134
135 CREATE CERTIFICATE ${H}_cert WITH SUBJECT = '$H certificate';
136 GO
137
138 CREATE ENDPOINT Endpoint_Mirroring
139 STATE = STARTED
140 AS TCP (
141 LISTENER_PORT=7024
142 , LISTENER_IP = ALL
143 )
144 FOR DATABASE_MIRRORING (
145 AUTHENTICATION = CERTIFICATE ${H}_cert
146 , ENCRYPTION = REQUIRED ALGORITHM AES
147 , ROLE = ALL
148 );
149 GO
150
151 BACKUP CERTIFICATE ${H}_cert TO FILE = '$Folder\certificate.cer';
152 GO
153 "
154
155 Invoke-SQLText -SQL $CreateMasteeKey
156}
157
37Export-ModuleMember -Function New-SQLServer 158Export-ModuleMember -Function New-SQLServer
38Export-ModuleMember -Function Remove-SQLServer 159Export-ModuleMember -Function Remove-SQLServer
160Export-ModuleMember -Function Invoke-SQLText
161Export-ModuleMember -Function Initialize-MirroringEndpoint