#!/bin/ksh # ====================================================================== # Richard Wilson - 28.04.2017 # Backup the database using Data Pump. # ---------------------------------------------------------------------- # History: # RW 02.06.2014 Minor modifications. # RW 24.06.2014 Parallelised. # EXPDP to ASM only. # RW 26.06.2014 Added ASM dump file deletion. # RW 04.09.2014 Use dynamic date, changed ORACLE_HOME. # Corrected errors in ASM purge. # # ====================================================================== # OWNER DIRECTORY_NAME DIRECTORY_PATH # ---------- -------------- ------------------------------------------- # SYS DUMPSET_LOGS create or replace directory DUMPSET_LOGS as '/home/oracle/Scripts/DP/logs'; # SYS DUMPSETS +R5DISK/CONV/dumpset # ---------------------------------------------------------------------- function is_sid_valid { if [ `ps -ef | grep -v grep | grep "ora_pmon_${ORACLE_SID}$" | wc -l 2> /dev/null` -eq 0 ] then return 1 else return 0 fi } function get_db_size { res=`sqlplus -s expman/expdp@${ORACLE_SID} <<-EOF SET ECHO OFF NEWP 0 SPA 0 PAGES 0 FEED OFF HEAD OFF TRIMS ON TAB OFF column bytes format 99999999999999999 select sum(bytes) bytes from dba_extents; exit EOF` echo ${res} } # ---------------------------------------------------------------------- export ORACLE_SID=`echo ${1} | tr "[a-z]" "[A-Z]"` export SIZE_FLAG="${2}" export ORACLE_HOME="/u01/app/oracle/product/11.2.0/dbhome_1" export SCRIPTS_DIR="/home/oracle/Scripts/DP" if [ "$#" -ge 1 ] && [ "$#" -le 2 ] then if is_sid_valid then SIZE=`get_db_size` echo `get_db_size` echo "SIZE is ${SIZE}." case ${SIZE_FLAG} in I|i) export SIZE_FLAG="";; E|e) export SIZE_FLAG="exclude=SCHEMA:\"in \(\'MDMADM\',\'CCBADM\'\)\"";; *) exit;; esac # Check for log file, and if exists, rename. [ -f ${SCRIPTS_DIR}/logs/${ORACLE_SID}_`date '+%a'`_daily_expdp.log ] && mv -f ${SCRIPTS_DIR}/logs/${ORACLE_SID}_`date '+%a'`_daily_expdp.log ${SCRIPTS_DIR}/logs/old_${ORACLE_SID}_`date '+%a'`_daily_expdp.log || : # Export the database. echo ${ORACLE_HOME}/bin/expdp expman/expdp@${ORACLE_SID} dumpfile=EXP_DIR:${ORACLE_SID}_`date '+%a'`_daily_expdp_%U.dmp full=y ${SIZE_FLAG} logfile=DUMPSET_LOGS:${ORACLE_SID}_`date '+%a'`_daily_expdp.log reuse_dumpfiles=y #parallel# # Purge old EXPDP files from ASM. if [ $? -eq 0 ] then export ORACLE_SID="+ASM" export ORACLE_HOME="/u01/app/oracle/product/11.2.0/grid" #last_day=`date +%a --date='3 days ago'` #${ORACLE_HOME}/bin/asimcmd rm -f +R5DISK/CONV/dumpset/CONV_${last_day}_daily_expdp_*.dmp fi else echo -e "ERROR: Parameter 1: Database '${ORACLE_SID}' does not exist." fi else echo -e "ERROR: Usage daily_expdp_v4.ksh nclude|xclude MDM/CCB Data." fi # =============================================================================================================