weekly_expdp_v2.ksh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 - RW - Removed 28.04.2017.
  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. # RW 28.04.2017 Modified for tst-02
  14. # RW 28.04.2017 Added Database Sizing function.
  15. # RW 07.06.2017 Modified for Weekly backups.
  16. #
  17. # ============================================================================================================
  18. # OWNER DIRECTORY_NAME DIRECTORY_PATH
  19. # ---------- -------------- ---------------------------------------------------------------------------------
  20. # SYS DUMPSET_LOGS /home/oracle/Scripts/DP/logs
  21. # SYS EXP_DIR +DATA/<${ORACLE_SID}>/DUMPSET
  22. # ------------------------------------------------------------------------------------------------------------
  23. function is_sid_valid
  24. {
  25. if [ `ps -ef | grep -v grep | grep "ora_pmon_${ORACLE_SID}$" | wc -l 2> /dev/null` -eq 0 ]
  26. then
  27. return 1
  28. else
  29. return 0
  30. fi
  31. }
  32. function get_db_size
  33. {
  34. res=`sqlplus -s expman/expdp@${ORACLE_SID} <<-EOF
  35. SET ECHO OFF NEWP 0 SPA 0 PAGES 0 FEED OFF HEAD OFF TRIMS ON TAB OFF
  36. column bytes format 99999999999999999
  37. select sum(bytes) bytes from dba_extents;
  38. exit
  39. EOF`
  40. echo ${res}
  41. }
  42. # ------------------------------------------------------------------------------------------------------------
  43. export DEBUG="N" # "Y"||"N"
  44. export ORACLE_SID=`echo ${1} | tr "[a-z]" "[A-Z]"`
  45. export DB_SID=${ORACLE_SID}
  46. export SIZE_FLAG=""
  47. export ORACLE_HOME="/u01/app/oracle/product/11.2.0/dbhome_1"
  48. export SCRIPTS_DIR="/home/oracle/Scripts/DP"
  49. if [ "$#" -eq 1 ]
  50. then
  51. if is_sid_valid
  52. then
  53. if [[ `get_db_size` -gt 10000000000 ]]
  54. then
  55. SIZE_FLAG="exclude=SCHEMA:\"in ('MDMADM','CCBADM')\""
  56. fi
  57. # Export the database.
  58. echo -e ${ORACLE_HOME}/bin/expdp expman/expdp@${ORACLE_SID} dumpfile=EXP_DIR:${ORACLE_SID}_week_`date '+%V'`_expdp.dmp full=y ${SIZE_FLAG} logfile=DUMPSET_LOGS:${ORACLE_SID}_week_`date '+%V'`_expdp.log reuse_dumpfiles=y
  59. # Purge from ASM..............
  60. if [ $? -eq 0 ]
  61. then
  62. [ -f ${SCRIPTS_DIR}/logs/${ORACLE_SID}_week_`date +%V --date='2 weeks ago'`_expdp.log ] && rm -f ${SCRIPTS_DIR}/logs/${ORACLE_SID}_week_`date +%V --date='2 weeks ago'`_expdp.log || :
  63. export ORACLE_SID="+ASM"
  64. export ORACLE_HOME="/u01/app/oracle/product/11.2.0/grid"
  65. # ${ORACLE_HOME}/bin/asmcmd rm -f +DATA/${DB_SID}/dumpset/${DB_SID}_week_`date +%V --date='2 weeks ago'`_expdp.dmp
  66. fi
  67. else
  68. echo -e "ERROR: Parameter 1: Database '${ORACLE_SID}' does not exist."
  69. fi
  70. else
  71. echo -e "ERROR: Usage weekly_expdp_v?.ksh <ORACLE_SID>."
  72. fi
  73. # =============================================================================================================