| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #!/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 - RW - Removed 28.04.2017.
- # 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.
- # RW 28.04.2017 Modified for tst-02
- # RW 28.04.2017 Added Database Sizing function.
- #
- # ============================================================================================================
- # OWNER DIRECTORY_NAME DIRECTORY_PATH
- # ---------- -------------- ---------------------------------------------------------------------------------
- # SYS DUMPSET_LOGS /home/oracle/Scripts/DP/logs
- # SYS EXP_DIR +DATA/<${ORACLE_SID}>/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="" # Set to NULL value.
- export ORACLE_HOME="/u01/app/oracle/product/11.2.0/db_1"
- export SCRIPTS_DIR="/home/oracle/Scripts/DP"
- if [ "$#" -eq 1 ]
- then
- if is_sid_valid
- then
- if [ `get_db_size` -gt 10000000000 ]
- then
- SIZE_FLAG="exclude=SCHEMA:\"in \(\'MDMADM\',\'CCBADM\'\)\""
- fi
- # 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.
- ${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 - .......use for later..........
- # if [ $? -eq 0 ]
- # then
- # export ORACLE_SID="+ASM"
- # export ORACLE_HOME="/u01/app/oracle/product/11.2.0/grid"
- #last_day=`date +%a --date='4 days ago'`
- #${ORACLE_HOME}/bin/asmcmd rm -f +DATA/${ORACLE_SID}/dumpset/${ORACLE_SID}_${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_v?.ksh <ORACLE_SID>."
- fi
- # =============================================================================================================
|