开发者社区> lemotree> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

oracle-audit-清除audit功能生成的os文件

简介:
+关注继续查看

清除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}


版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
oracle 11g rac 添加重做日志文件
1)实验思路: 【1】查看当前联机重做日志文件信息 【2】实验前进行必要的文件备份 【3】增加两组联机重做日志文件,每个文件大小为2G 【4】查看oracle运行状态,每个实例各一个,这样每个实例一共各有5个日志文件 【5】再次增加一组日志文件,每个实例各一...
997 0
10g Oracle文件及目录介绍
                                           10g Oracle文件及目录介绍                                                      作者:吴伟龙 文件类型:*.dbf             数据文件  是创建表空间生成的文件   主要存放数据 egg:table表,index索引,view视图,user用户。
799 0
【Oracle】一款非常好用的trace文件分析工具之二
前一篇文章介绍了如何安装trca,接下来介绍如何使用trca:必须进入 trca/run 目录里面 或者把 /home/oracle/software/trca/run 放到SQL_PATH环境变量里面: 使用trcanlzr.
1004 0
+关注
lemotree
地球村民
92
文章
0
问答
文章排行榜
最热
最新
相关电子书
更多
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
冬季实战营第三期:MySQL数据库进阶实战
立即下载