Escolar Documentos
Profissional Documentos
Cultura Documentos
#######
# Purpose: The script calls the Oracle Failsafe Cmdlet that adds the Oracle
database to
# the according and previously created Oracle Cluster Group.
#
# History:
# 02/2014 Created -mb-
# 01/2015 Write important messages and errors to a logfile.
#
#
###################################################################################
#######
function Get-ScriptDirectory
{
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
$logpath = $HOME
$logfile = $logpath+"\"+"AddOracleDbToOracleClusterGroup.log"
$seenerror = 0
function log_message([string]$logmessage)
{
$outtext = Get-Date -UFormat "%Y.%m.%d %H:%M:%S"
$outtext = $outtext +" " + $logmessage
$outtext | Out-File $logfile -Append
write-host $outtext
function FGetClusterHostName
{
$cluster = Get-Cluster
$res = $cluster.Name
return $res
}
function FGetDBSID
{
$regexp = "^[a-zA-Z][a-zA-Z0-9][a-zA-Z0-9]"
$forbidden =
"ADD","ALL","AND","ANY","ASC","AUX","COM","CON","DBA","END","EPS","FOR","GID","IBM"
,"INT","KEY","LOG","LPT","MON","NIX","NOT","NUL","OFF","OMS","PRN","RAW","ROW","SAP
","SET","SGA","SHG","SID","SQL","SYS","TMP","UID","USR","VAR"
do
{
$res = Read-Host -Prompt "Please enter the 3-letter/digit DBSID of the
Oracle database "
$res = $res.ToUpper()
if ($res.Length -ne 3)
{
write-host "invalid length"
$res = ""
}
if ($res -notmatch $regexp)
{
write-host "invalid input"
$res = ""
}
if ($res -contains $forbidden)
{
write-host "invalid/reserved DBSID"
$res = ""
}
} until ($res.Length)
return $res
}
function FGetClusterHostName
{
$cluster = Get-Cluster
$res = $cluster.Name
return $res
}
function FGetDBHostName
{
do
{
$res = Read-Host -Prompt "Please enter the virtual hostname (DNS) of the db
host "
$res = $res.ToUpper()
} until ($res.Length)
return $res
}
function FGetPFILE
{
do
{
$res = Read-Host -Prompt "Please enter path and filename of your Oracle
parameter file on the shared cluster disk "
$res = $res.ToUpper()
# if(-Not (Test-Path $res))
# {
# write-host "file not found"
# $res = ""
# }
} until ($res.Length)
return $res
}
function FGetYESNO($question)
{
do
{
$res = Read-Host -Prompt $question
$res = $res.ToUpper()
} until ($res.Length)
return $res
}
function FGetOracleHomePassword
{
write-host "If you are using Oracle release 11.x or 12.x *WITHOUT* Oracle Home
User just press ENTER"
write-host "If you are using Oracle release 12.x *WITH* Oracle Home User please
enter the password of the user"
$res = Read-Host -Prompt "Please enter the password or press ENTER to continue
" -AsSecureString
return $res
}
write-host "This script will add the Oracle Database to the Oracle Cluster Group"
write-host
"============================================================================"
try
{
$DBSID = FGetDBSID
$CLDNS = FGetClusterHostName
$DBGROUPNAME = "ORACLE"+$DBSID
$DBPFILE = FGetPFILE
$OHOMEPWD = FGetOracleHomePassword
log_message("DBSID = "+$DBSID)
log_message("CLDNS = "+$CLDNS)
log_message("DBGROUPNAME = "+$DBGROUPNAME)
log_message("DBPFILE = "+$DBPFILE)
write-host
write-host
"============================================================================"
write-host "PLEASE VERIFY IF THE DATA BELOW IS CORRECT BEFORE YOU CONTINUE"
write-host
"----------------------------------------------------------------------------"
write-host "CLUSTERNAME (virtual hostname of the cluster in DNS)
:"$CLDNS
write-host "DBSID (DB SID of the database)
:"$DBSID
write-host "Name of the Oracle Cluster Group
:"$DBGROUPNAME
write-host "Path+Filename of the Oracle initialization parameter file on shared
cluster disk :"$DBPFILE
write-host "This will add the Oracle database "$DBSID" to the cluster group
"$DBGROUPNAME
write-host
write-host "WARNING: If the Oracle database "$DBSID" is already part of a cluster
group it will be remove from the group first"
log_message("adding OracleClusterResource...")
$db = Get-OracleClusterResource -Available $DBSID -Verbose -ErrorAction
SilentlyContinue
$db.ParametersFile = $DBPFILE
if($OHOMEPWD.Length -gt 0)
{
log_message("using Oracle Home User Password")
$db.Home.ServiceUserPassword=$OHOMEPWD
}
$db | Add-OracleClusterResource -Group $DBGROUPNAME -Verbose -Confirm:$true
}
else
{
write-host "Exiting without modifications."
}
} # try
catch [Exception]
{
$seenerror = 1
$scripterror = $_.Exception.Message
$scriptline = $_.InvocationInfo.ScriptLineNumber
$scriptname = $_.InvocationInfo.ScriptName
if($seenerror -eq 0)
{
log_message("=== END OF SCRIPT EXECUTION: SUCCESS ===")
}
else
{
log_message("=== END OF SCRIPT EXECUTION: WITH ERROR(S) ===")
}