forked from dwheltzel/Shell-Scripts-for-Oracle-DBAs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCleanupOracleFiles.sh
More file actions
93 lines (75 loc) · 2.45 KB
/
CleanupOracleFiles.sh
File metadata and controls
93 lines (75 loc) · 2.45 KB
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
# Cleanup of filesystems by the root user
#
# Author: Dennis Heltzel 02/15/2022
export ORACLE_HOME=/opt/app/oracle/19c
DIAGDIR=/opt/app/oracle/diag/rdbms
LOG_DIR=~/logs
[ -d ${LOG_DIR} ] || mkdir -p ${LOG_DIR}
RUNDIR=`dirname "${BASH_SOURCE[0]}"`
. ${RUNDIR}/ora_funcs.sh
exec > ${LOG_DIR}/CleanupOracleFiles.log 2>&1
usage() {
echo "Usage: $0 [-i]"
echo " -l - interactive run"
exit 1
}
RUN_DATE=$(date +%y-%m-%d_%H%M%S)
# Handle parameters
while getopts "i:" opt; do
case $opt in
i)
INTERACTIVE=YES
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
;;
:)
echo "Option -$OPTARG requires an argument." >&2
usage
;;
esac
done
LOGFILE=${LOG_DIR}/CleanupOracleFiles.log
if [ "${USER}" == "root" ] ; then
# First, cleanup system files
journalctl --vacuum-time=1s
# Remove un-needed system files
#rm -rf /tmp/OraInstall*
rm -f /var/log/*.1
rm -f /var/log/*-20*
rm -f /var/log/*gz
# Clear the ones we do need to keep
#:> /var/spool/mail/root
#:> /var/log/rdbmsaudit.log
#:> /var/log/asmaudit.log
# Migrate schemas before we run purgelogs
ADR_HOME=`ls -d ${DIAGDIR}/*/${ORACLE_SID}|cut -c17-`
tty -s && echo $ADR_HOME
${ORACLE_HOME}/bin/adrci exec="set homepath $ADR_HOME; migrate schema"
# Fix permissions - If these pv dirs are owned by root, you can't login locally
#chown -R oracle /opt/app/oracle/diag/rdbms/*/*/metadata_pv
if [ -x ${RUNDIR}/purgeLogs ] ; then
${RUNDIR}/purgeLogs -orcl 1 -osw 1 -oda 1 -extra /tmp:1,/var/log:1
fi
fi
cd $DIAGDIR
# remove core dumps
rm -rf ${DIAGDIR}/*/*/trace/cdmp*
find /opt/app -name "cdmp*" -type d -delete
# remove incident files
rm -rf ${DIAGDIR}/*/*/incident/incdir*
DIAGDIR=/opt/app
# remove audit files
find /opt/app -mount -name "*.aud" -type f -delete
# remove zero length files older than 6 hours
find $DIAGDIR -mount -name "*.trc" -type f -size 0 -mmin +360 -delete
find $DIAGDIR -mount -name "*.trm" -type f -size 0 -mmin +360 -delete
# clear older trace files
find $DIAGDIR -mount -name "*.trc" -type f -size +0 -mmin +10 -execdir cp /dev/null {} \;
find $DIAGDIR -mount -name "*.trm" -type f -size +0 -mmin +10 -execdir cp /dev/null {} \;
# Clear of all large trace files
#find $DIAGDIR -mount -name "*.trc" -type f -size +0 -execdir cp /dev/null {} \;
#find $DIAGDIR -mount -name "*.trm" -type f -size +0 -execdir cp /dev/null {} \;
# Check ownership of directories
tty -s && ls -ld /opt/app/oracle/diag/rdbms/*/*/metadata_pv