-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclear_oracle_archlogs.sh
97 lines (80 loc) · 3.01 KB
/
clear_oracle_archlogs.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
#!/bin/bash
################################################################################
# #
# Скрипт удаления архивных логов через rman #
# mailto:[email protected]. #
# <2022.04.15> #
################################################################################
#
# Additional description:
# Requirements:
# TODO:
export PATH="$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
CLEAR_LOG_FILE=/var/tmp/del_rman_alogs.log
EXL_DB="\-MGMTDB|ASM|APX|ipmon"
# Count Instance Numbers
INS_COUNT=$(pgrep -fa pmon | grep -Ecv ${EXL_DB})
# Exit if No DBs are running:
if [ "$INS_COUNT" -eq 0 ]; then
echo "No Database Running">> $CLEAR_LOG_FILE
exit
fi
export ORACLE_BASE=''
# Loop for every Oracle Home in ORATAB file from /etc/oratab for a database
# Getting ORACLE_SID and ORACLE_HOME
for DBNAME in $(pgrep -af [o]ra_pmon |\
grep -Ev ${EXL_DB}|awk '{print $NF}' |\
sed -e 's/ora_pmon_//g' |\
grep -v "s///g"); do
ORACLE_SID=$(pgrep -af [o]ra_pmon |\
grep -i "${DBNAME^^}" |\
grep -Ev ${EXL_DB} |\
awk '{print $NF}' |\
sed -e 's/ora_pmon_//g' |\
grep -v "s///g")
ORACLE_HOME=$(grep "^${DBNAME}:" /etc/oratab |\
cut -d: -f2 -s)
for pid in $(pgrep -af pmon |\
grep "${ORACLE_SID}" |\
grep -Ev ${EXL_DB} |\
grep -v "\-MGMTDB" |\
awk '{print $1}'); do
ORA_USER=$(ps -o user= -p "$pid")
done
USR_ORA_HOME=$(grep -i "^${ORA_USER}:" /etc/passwd | cut -f6 -d ':' | tail -1)
# Getting ORACLE_BASE:
if [ ! -d "${ORACLE_BASE}" ]; then
ORACLE_BASE=$(grep ^ORACLE_BASE "${ORACLE_HOME}"/install/envVars.properties |\
tail -1 |\
awk '{print $NF}' |\
sed -e 's/ORACLE_BASE=//g')
export ORACLE_BASE
fi
if [ ! -d "${ORACLE_BASE}" ]; then
ORACLE_BASE=$(grep -h 'ORACLE_BASE=\/' "${USR_ORA_HOME}"/.bash* "${USR_ORA_HOME}"/.*profile |\
perl -lpe'$_ = reverse' |\
cut -f1 -d'=' |\
perl -lpe'$_ = reverse' |\
tail -1)
export ORACLE_BASE
fi
# Set Operating System Environment Variables
export ORACLE_SID
export ORACLE_HOME
#=================#
RMAN_LOG_FILE=$CLEAR_LOG_FILE
{
echo Script "$0"
echo ==== started on "$(date)" for "$ORACLE_SID" period time "sysdate-$1"====
echo ""
} >> $RMAN_LOG_FILE
export RMAN=$ORACLE_HOME/bin/rman
$RMAN target / nocatalog msglog $RMAN_LOG_FILE append <<EOF
# -----------------------------------------------------------------
# RMAN command section
# -----------------------------------------------------------------
RUN {
delete noprompt archivelog all completed before 'sysdate-$1';
}
EOF
done