New Datapump Export Script

Assumptions

The script assumes the following directory structure

/u01/app/oracle/admin/<Database Name>/dpdump
/u01/app/oracle/admin/<Database Name>/dpdump/FULL_BACKUPS
/u01/app/oracle/admin/<Database Name>/dpdump/LOGS

The script will also purge old exports and log files older than 7 days.

datapump_backup.ksh

#!/bin/ksh -x
#
# Title:     datapump_backup.ksh
# Purpose:   Used to take full datapump exports
# Called by: n/a
#
# Notes:     None
#
# Author:    Mark ramsay
# Date:      05 April 2012
#

LOGFILE=/var/log/oracle/exp_backup_rac_$(date +\%a).log
exec > $LOGFILE 2>&1

export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.1.0/dbhome_1
export PATH=$PATH:$ORACLE_HOME/bin
export NLS_LANG=American_America.UTF8

SDS_part=$(echo $1 |head -c3)
SDS_date=$(date +%d%b%Y)
export SDS_DBNAME=$1
export ORACLE_SID=$(ps -ef |grep pmon |grep $SDS_part |awk '{print $8}' |awk -F\_ '{print $3}' |sed -e 's/ //')
export ORAENV_ASK=NO

. oraenv

expdp \"/ as sysdba\" DUMPFILE=${SDS_DBNAME}_full_backup_${SDS_date}.dmp DIRECTORY=${SDS_DBNAME}_DATAPUMP Full=y LOGFILE=${SDS_DBNAME}_full_backup_${SDS_date}.log

cd /u01/app/oracle/admin/${SDS_DBNAME}/dpdump/FULL_BACKUPS
mv /u01/app/oracle/admin/${SDS_DBNAME}/dpdump/${SDS_DBNAME}_full_backup_${SDS_date}.dmp .
gzip -f ${SDS_DBNAME}_full_backup_${SDS_date}.dmp

#
# Move Logs
#

cd /u01/app/oracle/admin/${SDS_DBNAME}/dpdump/LOGS
mv ../${SDS_DBNAME}_full_backup_${SDS_date}.log .

#
# Delete old files
#

cd /u01/app/oracle/admin/${SDS_DBNAME}/dpdump/LOGS
find . -name "${SDS_DBNAME}_full_backup_${SDS_date}.log" -mtime +7 -follow -exec rm {} \;

cd /u01/app/oracle/admin/${SDS_DBNAME}/dpdump/FULL_BACKUPS
find . -name "${SDS_DBNAME}_full_backup_${SDS_date}.dmp.gz" -mtime +7 -follow -exec rm {} \;

exit 0
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License