daily_expdp_v5.ksh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/ksh
  2. # ======================================================================
  3. # Richard Wilson - 28.04.2017
  4. # Backup the database using Data Pump.
  5. # ----------------------------------------------------------------------
  6. # History:
  7. # RW 02.06.2014 Minor modifications.
  8. # RW 24.06.2014 Parallelised.
  9. # EXPDP to ASM only.
  10. # RW 26.06.2014 Added ASM dump file deletion.
  11. # RW 04.09.2014 Use dynamic date, changed ORACLE_HOME.
  12. # Corrected errors in ASM purge.
  13. #
  14. # ======================================================================
  15. # OWNER DIRECTORY_NAME DIRECTORY_PATH
  16. # ---------- -------------- -------------------------------------------
  17. # SYS DUMPSET_LOGS create or replace directory DUMPSET_LOGS as '/home/oracle/Scripts/DP/logs';
  18. # SYS DUMPSETS +R5DISK/CONV/dumpset
  19. # ----------------------------------------------------------------------
  20. function is_sid_valid
  21. {
  22. if [ `ps -ef | grep -v grep | grep "ora_pmon_${ORACLE_SID}$" | wc -l 2> /dev/null` -eq 0 ]
  23. then
  24. return 1
  25. else
  26. return 0
  27. fi
  28. }
  29. function get_db_size
  30. {
  31. res=`sqlplus -s expman/expdp@${ORACLE_SID} <<-EOF
  32. SET ECHO OFF NEWP 0 SPA 0 PAGES 0 FEED OFF HEAD OFF TRIMS ON TAB OFF
  33. column bytes format 99999999999999999
  34. select sum(bytes) bytes from dba_extents;
  35. exit
  36. EOF`
  37. echo ${res}
  38. }
  39. # ----------------------------------------------------------------------
  40. export ORACLE_SID=`echo ${1} | tr "[a-z]" "[A-Z]"`
  41. export SIZE_FLAG="${2}"
  42. export ORACLE_HOME="/u01/app/oracle/product/11.2.0/dbhome_1"
  43. export SCRIPTS_DIR="/home/oracle/Scripts/DP"
  44. if [ "$#" -ge 1 ] && [ "$#" -le 2 ]
  45. then
  46. if is_sid_valid
  47. then
  48. SIZE=`get_db_size`
  49. echo `get_db_size`
  50. echo "SIZE is ${SIZE}."
  51. case ${SIZE_FLAG} in
  52. I|i) export SIZE_FLAG="";;
  53. E|e) export SIZE_FLAG="exclude=SCHEMA:\"in \(\'MDMADM\',\'CCBADM\'\)\"";;
  54. *) exit;;
  55. esac
  56. # Check for log file, and if exists, rename.
  57. [ -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 || :
  58. # Export the database.
  59. 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#
  60. # Purge old EXPDP files from ASM.
  61. if [ $? -eq 0 ]
  62. then
  63. export ORACLE_SID="+ASM"
  64. export ORACLE_HOME="/u01/app/oracle/product/11.2.0/grid"
  65. #last_day=`date +%a --date='3 days ago'`
  66. #${ORACLE_HOME}/bin/asimcmd rm -f +R5DISK/CONV/dumpset/CONV_${last_day}_daily_expdp_*.dmp
  67. fi
  68. else
  69. echo -e "ERROR: Parameter 1: Database '${ORACLE_SID}' does not exist."
  70. fi
  71. else
  72. echo -e "ERROR: Usage daily_expdp_v4.ksh <ORACLE_SID> <I>nclude|<E>xclude MDM/CCB Data."
  73. fi
  74. # =============================================================================================================