-
Notifications
You must be signed in to change notification settings - Fork 0
/
reclaim.sh
executable file
·148 lines (121 loc) · 3.58 KB
/
reclaim.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#############################################################
# Set the appropriate environmental variables #
#############################################################
##
## Set Oracle Specific Environmental env's
##
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export ORACLE_SID="oggsrc"
DBROLE=""
RESTORE_USER=`whoami`
##
## For Warning and Text manupulation
##
bold=$(tput bold)
reset=$(tput sgr0)
bell=$(tput bel)
underline=$(tput smul)
#############################################################
# Functions to handle exceptions and erros #
#############################################################
###
### Handling error while running script
###
### $1 : Error Code
### $2 : Error message in detail
###
ReportError(){
echo "########################################################"
echo "Error during Running Script"
echo -e "$1: $2"
echo "########################################################"
exit 1;
}
ReportInfo(){
echo "########################################################"
echo "Information by the script : $CURSCRIPT"
echo -e "INFO : $1 "
echo "########################################################"
}
###
### FUNCTION TO CHECK FUNDAMENTAL VARIABLES
###
CheckVars(){
if [ "${1}" = "" ]
then
ReportError "RERR-001" "${bell}${bold}${underline}ORACLE_HOME${reset} Env variable not Set. Aborting...."
elif [ ! -d ${1} ]
then
ReportError "RERR-002" "Directory \"${bell}${bold}${underline}${1}${reset}\" not found or ORACLE_HOME Env invalid. Aborting...."
elif [ ! -x ${1}/bin/sqlplus ]
then
ReportError "RERR-003" "Executable \"${bell}${bold}${underline}${1}/bin/sqlplus${reset}\" not found; Aborting..."
elif [ "${2}" = "" ]
then
ReportError "RERR-004" "${bell}${bold}${underline}ORACLE_SID${reset} Env variable not Set. Aborting..."
elif [ "${3}" != "oracle" ]
then
ReportError "RERR-004" "User "${bell}${bold}${underline}${3}${reset}" not valid for running script; Aborting..."
else
return 0;
fi
}
checkSidValid(){
param1=("${!1}")
check=${2}
statusSID=0
for i in ${param1[@]}
do
if [ ${i} == $2 ];
then
statusSID=1
break
esle
echo $i;
fi
done
return $statusSID;
}
###
### Get Oracle SID env
###
FunGetOracleSID(){
myarr=($(ps -ef | grep ora_smon| grep -v grep | awk -F' ' '{print $NF}' | cut -c 10-))
checkSidValid myarr[@] ${ORACLE_SID}
if [ $? -eq 0 ]
then
ReportError "\nRERR-005" "ORACLE_SID : ${bell}${bold}${underline}${ORACLE_SID}${reset} Env is invalid, no instance is running. Aborting..."
fi
ReportInfo "\nChecking for validness for ORACLE_SID: ${bell}${bold}${underline}${ORACLE_SID}${reset} passed....."
}
###
### Get the Database open mode...
###
FunGetDBRole(){
DBROLE=$($1/bin/sqlplus -s /nolog <<END
set pagesize 0 feedback off verify off echo off;
connect / as sysdba
select DATABASE_ROLE from v\$database;
END
)
}
FunRestartMR(){
DBROLE=$($1/bin/sqlplus -s /nolog <<END
set pagesize 0 feedback off verify off echo off;
connect / as sysdba
alter database recover managed standby database cancel;
alter database recover managed standby database using current logfile disconnect from session;
END
)
}
CheckVars ${ORACLE_HOME} ${ORACLE_SID} ${RESTORE_USER}
FunGetDBRole ${ORACLE_HOME}
if [ "${DBROLE}" = "PHYSICAL STANDBY" ]
then
ReportInfo "\nReclaiming Space............"
rm -f /u01/app/oracle/diag/rdbms/oggsrc/oggsrc/trace/*.trc
rm -f /u01/app/oracle/diag/rdbms/oggsrc/oggsrc/trace/*.trm
FunRestartMR ${ORACLE_HOME}
else
ReportInfo "\nDatabase is not Standby database"
fi