清除oracle数据库audit功能生成的os文件
--注:dataguard库无法执行
BEGIN
dbms_audit_mgmt.clean_audit_trail(audit_trail_type => dbms_audit_mgmt.audit_trail_os,
use_last_arch_timestamp => FALSE);
END;
/
/*
os command
cd $ORACLE_HOME/rdbms/audit
find ./ -name "*.aud" |xargs -i rm -f {}
*/
--------------------shell脚本 ----------
#########################################################################################################################
#NOTE:
#use for AIX、LINUX
#This script is used to purge oracle audit files using procedure dbms_audit_mgmt.clean_audit_trail on primary site
# or purge audit file by OS command on standbyDB site
# Version:
# 2.0 modified by tiger , added purge audit file by OS commadn on standbyDB site.
#
#Usage:
# 1.execute this script as oracle user
# linux crontab example:
# 00 00 01 * * /bin/sh /home/oracle/scripts/purge_auditfile_using_sql.sh >/dev/null 2>&1
#aix crontab example:
#00 00 1 * * /u01/app/oracle/scripts/purge_auditfile_using_sql.sh > /dev/null 2>&1
###########################################################################################################################
#!/bin/sh
current_dir=$(cd `dirname $0`; pwd)
logfile=${current_dir}/purge_auditfile_$(date +"%Y%m%d_%H%M%S").log
find ${current_dir} -name "purge_auditfile_*.log" |xargs -i rm -f {} | tee -a ${logfile}
EXECUSER=`whoami`
platform=`uname | tr A-Z a-z`
echo ""| tee -a ${logfile}
echo `date "+%Y-%m-%d %H:%M:%S"`" begin"| tee -a ${logfile}
echo "---------------------------"|tee -a ${logfile}
echo ""| tee -a ${logfile}
echo "current_user: ${EXECUSER}"|tee -a ${logfile}
echo "os platform: ${platform}"|tee -a ${logfile}
echo "os current dir: ${current_dir}"|tee -a ${logfile}
echo "logfile : ${logfile}"|tee -a ${logfile}
echo ""| tee -a ${logfile}
echo "----------------------------"|tee -a ${logfile}
case $platform in
"linux")
. /home/$EXECUSER/.bash_profile
;;
"aix")
. /home/$EXECUSER/.profile
;;
esac
#get db role
oracle_database_role=`sqlplus -S / as sysdba <<EOF
set heading off feedback off pagesize 0 verify off echo off trims off
select database_role from v\\$database;
exit;
EOF`
#get db audit_file_dir
oracle_audit_file_dest=`sqlplus -S / as sysdba <<EOF
set heading off feedback off pagesize 0 verify off echo off trims off
SELECT display_value FROM v\\$parameter WHERE name='audit_file_dest';
exit;
EOF`
#if primary,purge by sql command
if [ "$oracle_database_role" = "PRIMARY" ] ; then
echo "oracle_database_role : ${oracle_database_role},so purge oracle audit files using procedure dbms_audit_mgmt.clean_audit_trail."|tee -a ${logfile}
sqlplus / as sysdba <<EOF
BEGIN
dbms_audit_mgmt.clean_audit_trail(audit_trail_type => dbms_audit_mgmt.audit_trail_os,
use_last_arch_timestamp => FALSE);
END;
/
exit;
EOF
else
# if standby,purge by os command.
echo ""| tee -a ${logfile}
echo "------------------------------" |tee -a ${logfile}
echo "oracle_database_role : ${oracle_database_role},so purge audit file by OS command."|tee -a ${logfile}
echo ""| tee -a ${logfile}
echo "------------------------------" |tee -a ${logfile}
echo "oracle_audit_file_dest : ${oracle_audit_file_dest}"|tee -a ${logfile}
echo ""| tee -a ${logfile}
find ${oracle_audit_file_dest} -type f -name "*.aud" |xargs -i rm {}
fi
if [ $? -gt 0 ]; then
echo "`date "+%Y-%m-%d %H:%M:%S"` failed.exit!" | tee -a ${logfile}
exit 1
fi
echo ""| tee -a ${logfile}
echo `date "+%Y-%m-%d %H:%M:%S"`" finished!"| tee -a ${logfile}
echo "-------------------------------" | tee -a ${logfile}