UNIX ADMINISTRATION
http://dbawiki.wordpress.com/
Oracle logs clearing on Linux hosts
Oracle logs clearing on Linux hosts
06Aug
Every two weeks on Linux hosts with Oracle RAC runs this script (/home/oracle/log_backup.sh). It deletes logs older 14 days from /u01/app/ folder. Archives big current log files (alert.log, listener.log) to folder /u01/app/oracle/log_backup/ and nullifies them.
It runs every second and fourth friday of every month at 1:15 am through crontab. The script’s logs are in u01/app/oracle/log_backup/.
It runs every second and fourth friday of every month at 1:15 am through crontab. The script’s logs are in u01/app/oracle/log_backup/.
cd /u01/app/oracle
mkdir log_backup
chmod 700 /home/oracle/log_backup.sh
chmod 700 /home/oracle/mv_log_backup.sh
#Runs every second and fourth friday of every month at 1:15 am.
crontab -l
crontab -e
15 1 8-14,22-28 * Fri /home/oracle/log_backup.sh >> /u01/app/oracle/log_backup/log_backup.log 2>&1
15 3 8-14,22-28 * Fri /home/oracle/mv_log_backup.sh
#log_backup.sh
#Deletes logs older 14 days from /u01/app/ folder. Archives big current log files.
export timestamp=$( date +%d.%m.%y_%H.%M.%S )
echo "------------------------------< Start Running at $timestamp >------------------------------"
#Find out what are the biggest logs
#du -BM /u01/app | sort -nr | grep 'log\|diag' | more
#find /u01/app -type f -mtime +14 | xargs ls -Slh | more
#find /u01/app -type f | grep 'log\|diag' | xargs ls -Slh | more
#find /u01/app -size +512M | xargs ls -Slh
#Drop log backups older then 14 days
#find /u01/app/oracle/log_backup/ -type f -mtime +14 | xargs ls -Slh | more
find /u01/app/oracle/log_backup/ -type f -mtime +14 | xargs /bin/rm -f
#Drop all logs older then 14 days
#find /u01/app/oracle/diag -type f -mtime +14 | xargs ls -Slh | more
#find /u01/app/11.2.0/grid112020/cdata -type f -mtime +14 | xargs ls -Slh
find /u01/app/oracle/diag -type f -mtime +14 | xargs /bin/rm -f
find /u01/app/oracle/*diag/diag -type f -mtime +14 | xargs /bin/rm -f
find /u01/app/oracle/product/11.2.0/*/log/diag/tnslsnr/*/listener/alert -type f -mtime +14 | xargs /bin/rm -f
find /u01/app/oracle/product/11.2.0/*/rdbms/log -type f -mtime +14 | xargs /bin/rm -f
find /u01/app/11.2.0/grid112020/log -type f -mtime +14 | xargs /bin/rm -f
find /u01/app/oracle/OracleHomes*/agent10g/*/sysman/log -type f -mtime +14 | xargs /bin/rm -f
find /u01/app/11.2.0/grid*/cv/log -type f -mtime +14 | xargs /bin/rm -f
#Clear alert.logs in /u01/app/oracle/diag/ folder
#find /u01/app/oracle/diag/ -type f -name 'alert*.log' | xargs ls -lh
for item in $(find /u01/app/oracle/diag/ -type f -name 'alert*.log') ;do
zip -9 -r /u01/app/oracle/log_backup/log_backup.zip $item
cat /dev/null > $item ;done
#Clear listener.logs in /u01/app/oracle/diag/ folder
#find /u01/app/oracle/diag/ -type f -name 'listener*.log' | xargs ls -lh
for item in $(find /u01/app/oracle/diag/ -type f -name 'listener*.log') ;do
zip -9 -r /u01/app/oracle/log_backup/log_backup.zip $item
cat /dev/null > $item ;done
#Clear listener log.xmls in /u01/app/oracle/diag/ folder
#find /u01/app/oracle/diag/ -type f -name 'log*.xml' | xargs ls -lh
for item in $(find /u01/app/oracle/diag/ -type f -name 'log*.xml') ;do
zip -9 -r /u01/app/oracle/log_backup/log_backup.zip $item
cat /dev/null > $item ;done
#Clear listener.logs in /u01/app/11.2.0/grid112020/log folder
#find /u01/app/11.2.0/grid112020/log -type f -name 'listener*.log' | xargs ls -Slh
for item in $(find /u01/app/11.2.0/grid112020/log -type f -name 'listener*.log') ;do
zip -9 -r /u01/app/oracle/log_backup/log_backup.zip $item
cat /dev/null > $item ;done
#Clear logs in /u01/app/11.2.0/grid112020/opmn/logs folder
#find /u01/app/11.2.0/grid112020/opmn/logs -type f -name '*.log.*'| xargs ls -Slh
for item in $(find /u01/app/11.2.0/grid112020/opmn/logs -type f -name '*.log.*') ;do
zip -9 -r /u01/app/oracle/log_backup/log_backup.zip $item
cat /dev/null > $item ;done
#Clear listener.logs in /u01/app/oracle/product/11.2.0/*/log/ folder
#find /u01/app/oracle/product/11.2.0/*/log/ -type f -name 'listener*.log' | xargs ls -lh
for item in $(find /u01/app/oracle/product/11.2.0/*/log/ -type f -name 'listener*.log') ;do
zip -9 -r /u01/app/oracle/log_backup/log_backup.zip $item
cat /dev/null > $item ;done
mv /u01/app/oracle/log_backup/log_backup.zip /u01/app/oracle/log_backup/log_backup_"$timestamp".zip
echo "------------------------------< End Running at $timestamp >------------------------------"
#mv_log_backup.sh
#Renames the log file to include date and time
export timestamp=$( date +%d.%m.%y_%H.%M.%S )
mv /u01/app/oracle/log_backup/log_backup.log /u01/app/oracle/log_backup/log_backup_"$timestamp".log
I really love it and amazing information in this blog. it's really good and great information well done. UNIX and Linux Administration.
ReplyDelete