<# .NOTES =========================================================================== Created with: SAPIEN Technologies, Inc., PowerShell Studio 2017 v5.4.136 Created on: 09/03/2017 12:28 Created by: Administrator Organization: Filename: =========================================================================== .DESCRIPTION A description of the file. #> param ( [parameter(Mandatory = $true)] [string]$EXPORTPATH ) function get-registryvalue($registrykey, $registryvalue) { $key = get-item -path "registry::$registrykey" $key.getvaluenames() | foreach-object { $name = $_ $rv = 1 | select-object -property name, type, value $rv.name = $name $rv.type = $key.getvaluekind($name) $rv.value = $key.getvalue($name) if ($rv.name -eq $registryvalue) { return $rv.value } } } $registrykey = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\DualShield" $registryvalue = "ImagePath" $dir = get-registryvalue $registrykey $registryvalue $global:path = $dir -replace '"' -replace "\\tomcat.*" $CPWD = (Get-Location).Path [xml]$server = Get-Content $path\tomcat\conf\server.xml [string]$username = $server.server.GlobalNamingResources.resource | %{ $_.username } $global:UN = $username.trim() [string]$password = $server.server.GlobalNamingResources.resource | %{ $_.password } $global:PW = $password.trim() foreach ($resource in $server.server.GlobalNamingResources.resource) { if($resource.factory -eq "com.deepnet.dualshield.encryption.EncryptedDataSourceFactory"){ cd $path\jre\bin $global:PW = cmd /c "java.exe -jar ..\..\tomcat\lib\dsenc-1.0-standalone.jar" -d $password.trim() } } [string]$DBName = $server.server.GlobalNamingResources.resource | %{ $_.url -replace "^.*.3306/" -replace "\?.*"} cd $path\mysql\bin function Back_DS { [CmdletBinding()] param ( [Parameter(Mandatory = $true, Position = 1)] [ValidateScript({ test-path $_ })] $EPath ) cmd /c "mysqldump --skip-lock-tables --single-transaction --flush-logs --hex-blob -u$UN -p""$PW"" $DBName > $EPath\MySQLBAK.sql" Copy-Item "$path\tomcat\conf\server.xml" "$EPath\Server.xml" -Recurse Copy-Item "$path\tomcat\conf\server.xml" "$EPath\context.xml" -Recurse Copy-Item "$path\certs" "$EPath" -Recurse Copy-Item "$path\config" "$EPath" -Recurse Copy-Item "$path\jre\lib\security\cacerts" "$EPath\cacerts" -Recurse if ($PSVersionTable.Psversion -ge "3.0") { Add-Type -assembly "system.io.compression.filesystem" [system.io.compression.zipfile]::CreateFromDirectory("$EPath", "$EPath.zip") Remove-Item $EPath -Recurse } } function get-exportpath { param ( [Parameter(Mandatory = $true, ValueFromPipeline = $true)] [ValidateScript({ test-path $_ })] $ExportPath ) $BakPath = "$ExportPath\DualShieldBAK_$([datetime]::Now.ToString('yyyyMMdd'))" $BakPathExsit = "$ExportPath\DualShieldBAK_$([datetime]::Now.ToString('yyyyMMdd-HHmm'))" if (!(Test-Path $ExportPath)) { New-Item $BakPath -Type directory Back_DS $BakPath } else { if ($(Test-Path "$BakPath*")) { New-Item $BakPathExsit -Type directory Back_DS $BakPathExsit } else { New-Item $BakPath -Type directory Back_DS $BakPath } } } get-exportpath $EXPORTPATH