oracle@shsub:/opt/oradiag/diag/rdbms/shsub/shsub/trace>cat /export/home/oracle/scripts/bin/expdp_full_all_DBs.ksh
#!/bin/ksh
set -x
# Script to do an export datapump of database, compress it, and delete dumps older than 7 days
. ~oracle/.profile
#/ora_share_nfs/scripts/expdp_full.ksh shsub /opt/app/oracle/product/11.2.0/11.2.0.4 EXPDP_DUMPDIR 4 5G 7 /ora_share_nfs/backup/shsub
#/ora_share_nfs/scripts/expdp_full.ksh shwm /opt/app/oracle/product/11.2.0/11.2.0.4 EXPDP_DUMPDIR 4 5G 7 /ora_share_nfs/backup/shwm
/ora_share_nfs/scripts/expdp_full_audit_and_wallet.ksh shsub /opt/app/oracle/product/11.2.0/11.2.0.4 EXPDP_DUMPDIR 4 5G 7 /ora_share_nfs/hmaissubdb01/shsub
/ora_share_nfs/scripts/expdp_full_audit_and_wallet.ksh shwm /opt/app/oracle/product/11.2.0/11.2.0.4 EXPDP_DUMPDIR 4 5G 7 /ora_share_nfs/hmaissubdb01/shwm
oracle@shsub:/opt/oradiag/diag/rdbms/shsub/shsub/trace>cat /ora_share_nfs/scripts/expdp_full.ksh
#!/bin/ksh
#set -x
# Usage:
# /export/home/oracle/scripts/bin/expdp_full.ksh
# parameters $ORACLE_SID $ORACLE_HOME EXPDP_DIR NO_PARALLEL FILESIZE RETENTION DEST_DIR
#
# Sample
# /export/home/oracle/scripts/bin/expdp_full.ksh dktms /opt/app/oracle/product/11.2.0/11.2.0.3 EXPDP_DUMPDIR 4 5G 7 /ora_share_nfs/kmaistmsdb/dktms
# /export/home/oracle/scripts/bin/expdp_full.ksh dktms2 /opt/app/oracle/product/11.2.0/11.2.0.3 EXPDP_DUMPDIR 4 5G 7 /ora_share_nfs/kmaistmsdb/dktms2
# /export/home/oracle/scripts/bin/expdp_full.ksh dktms3 /opt/app/oracle/product/11.2.0/11.2.0.3 EXPDP_DUMPDIR 4 5G 7 /ora_share_nfs/kmaistmsdb/dktms3
# /export/home/oracle/scripts/bin/expdp_full.ksh dktms4 /opt/app/oracle/product/11.2.0/11.2.0.3 EXPDP_DUMPDIR 4 5G 7 /ora_share_nfs/kmaistmsdb/dktms4
# /export/home/oracle/scripts/bin/expdp_full.ksh dktms /opt/app/oracle/product/11.2.0/11.2.0.3 EXPDP_DUMPDIR 4 5G 7 /ora_share_nfs/kmaistmsdb/sktms
# /export/home/oracle/scripts/bin/expdp_full.ksh dktms3 /opt/app/oracle/product/11.2.0/11.2.0.3 EXPDP_DUMPDIR 4 5G 7 /ora_share_nfs/kmaistmsdb/sktms3
# /export/home/oracle/scripts/bin/expdp_full.ksh dktms4 /opt/app/oracle/product/11.2.0/11.2.0.3 EXPDP_DUMPDIR 4 5G 7 /ora_share_nfs/kmaistmsdb/sktms4
#
. ~oracle/.profile
# Script to do an export datapump of database, compress it, and delete dumps older than 7 days
# Variables go here. Change according to environment and needs
RUN_DATE=`date "+%m%d%Y_%H%M%S"`
export ORACLE_SID=$1
export ORACLE_HOME=$2
export EXPDP_DIR=$3
export NO_PARALLEL=$4
export FILESIZE=$5
export RETENTION=$6
export DEST_DIR=$7
export HOSTNAME=`hostname`
export LOG_FILE_01=/export/home/oracle/scripts/logs/${ORACLE_SID}_expdp_full_01.log
export LOG_FILE_02=/export/home/oracle/scripts/logs/${ORACLE_SID}_expdp_full_02.log
echo "parameters: " $ORACLE_SID $ORACLE_HOME $EXPDP_DIR $NO_PARALLEL $FILESIZE $RETENTION $DEST_DIR
MAIL_TO='his-dba-alerts@hke.local'
# End of variables
# Remove old dmp files (generated by manually or from previous failed job)
ls $DEST_DIR/*full*dmp
ls $DEST_DIR/*full*dmp > $LOG_FILE_01
#grep "No such file or directory" $LOG_FILE_01 > $LOG_FILE_02
#grep "dmp" $LOG_FILE_01 > $LOG_FILE_02
if [ -s $LOG_FILE_01 ];then
rm $DEST_DIR/*full*dmp
fi
if [ $NO_PARALLEL -eq '0' ]; then
# expdp \"\/ as sysdba\" full=y directory=${EXPDP_DIR} dumpfile=${ORACLE_SID}_full_${RUN_DATE}_%U.dmp filesize=${FILESIZE} logfile=${ORACLE_SID}_full_${RUN_DATE}.log compression=all EXCLUDE=STATISTICS
$ORACLE_HOME/bin/expdp \"\/ as sysdba\" full=y directory=${EXPDP_DIR} dumpfile=${ORACLE_SID}_full_${RUN_DATE}_%U.dmp filesize=${FILESIZE} logfile=${ORACLE_SID}_full_${RUN_DATE}.log EXCLUDE=STATISTICS
else
# expdp \"\/ as sysdba\" full=y directory=${EXPDP_DIR} dumpfile=${ORACLE_SID}_full_${RUN_DATE}_%U.dmp parallel=${NO_PARALLEL} filesize=${FILESIZE} logfile=${ORACLE_SID}_full_${RUN_DATE}.log compression=all EXCLUDE=STATISTICS
$ORACLE_HOME/bin/expdp \"\/ as sysdba\" full=y directory=${EXPDP_DIR} dumpfile=${ORACLE_SID}_full_${RUN_DATE}_%U.dmp parallel=${NO_PARALLEL} filesize=${FILESIZE} logfile=${ORACLE_SID}_full_${RUN_DATE}.log EXCLUDE=STATISTICS
fi
EXPDP_STATUS=$?
echo
echo "EXPDP_STATUS: " $EXPDP_STATUS
echo
if [ ${EXPDP_STATUS} -eq 0 ]; then
sqlplus / as sysdba <<EOF
-- Backup spfile by create pfile from spfile.
create pfile='${DEST_DIR}/init${ORACLE_SID}_${RUN_DATE}.ora' FROM spfile;
EOF
# Archive and compress backup
cd ${DEST_DIR}
tar cEvf ${ORACLE_SID}_full_${RUN_DATE}.tar ${DEST_DIR}/${ORACLE_SID}_full_${RUN_DATE}_*.dmp
TAR_STATUS=$?
echo
echo "TAR_STATUS: " $TAR_STATUS
echo
if [ ${TAR_STATUS} -eq 0 ]; then
gzip ${ORACLE_SID}_full_${RUN_DATE}.tar
GZIP_STATUS=$?
echo
echo "GZIP_STATUS: " $GZIP_STATUS
echo
if [ ${GZIP_STATUS} -eq 0 ]; then
#bzip2 ${ORACLE_SID}_full_${RUN_DATE}.tar
#BZIP2_STATUS=$?
#if [ ${BZIP2_STATUS} -eq 0 ]; then
#Delete original dumps
rm ${DEST_DIR}/${ORACLE_SID}_full_${RUN_DATE}_*.dmp
find ${DEST_DIR}/${ORACLE_SID}_full_* -mtime +${RETENTION} -exec rm -f {} \;
find ${DEST_DIR}/init${ORACLE_SID}_*.ora -mtime +${RETENTION} -exec rm -f {} \;
echo "${ORACLE_SID}@$HOSTNAME: full export succeeded." | mailx -s "${ORACLE_SID}@$HOSTNAME: Backup by expdp Notification: SUCCESS" ${MAIL_TO}
else
#Do a cleanup
rm ${DEST_DIR}/${ORACLE_SID}_full_${RUN_DATE}_*.dmp
rm ${DEST_DIR}/${ORACLE_SID}_full_${RUN_DATE}.tar
echo "${ORACLE_SID}@$HOSTNAME: full export failed by gzip command." | mailx -s "${ORACLE_SID}@$HOSTNAME: Backup by expdp Notification: FAILED" ${MAIL_TO}
#echo "${ORACLE_SID}@$HOSTNAME: full export failed by gzip command." | mailx -s "${ORACLE_SID}@$HOSTNAME: Backup by expdp Notification: FAILED" ${MAIL_TO} < $DEST_DIR/${ORACLE_SID}_full_${RUN_DATE}.log
fi
else
#Do a cleanup
rm ${DEST_DIR}/${ORACLE_SID}_full_${RUN_DATE}_*.dmp
rm ${DEST_DIR}/${ORACLE_SID}_full_${RUN_DATE}.tar
rm ${DEST_DIR}/${ORACLE_SID}_full_${RUN_DATE}.tar.gz
echo "${ORACLE_SID}@$HOSTNAME: full export failed by tar command." | mailx -s "${ORACLE_SID}@$HOSTNAME: Backup by expdp Notification: FAILED" ${MAIL_TO}
#echo "${ORACLE_SID}@$HOSTNAME: full export failed by tar command." | mailx -s "${ORACLE_SID}@$HOSTNAME: Backup by expdp Notification: FAILED" ${MAIL_TO} < $DEST_DIR/${ORACLE_SID}_full_${RUN_DATE}.log
fi
else
echo "${ORACLE_SID}@$HOSTNAME: full export failed." | mailx -s "${ORACLE_SID}@$HOSTNAME: Backup by expdp Notification: FAILED" ${MAIL_TO}
#echo "${ORACLE_SID}@$HOSTNAME: full export failed." | mailx -s "${ORACLE_SID}@$HOSTNAME: Backup by expdp Notification: FAILED" ${MAIL_TO} < $DEST_DIR/${ORACLE_SID}_full_${RUN_DATE}.log
fi
#!/bin/ksh
set -x
# Script to do an export datapump of database, compress it, and delete dumps older than 7 days
. ~oracle/.profile
#/ora_share_nfs/scripts/expdp_full.ksh shsub /opt/app/oracle/product/11.2.0/11.2.0.4 EXPDP_DUMPDIR 4 5G 7 /ora_share_nfs/backup/shsub
#/ora_share_nfs/scripts/expdp_full.ksh shwm /opt/app/oracle/product/11.2.0/11.2.0.4 EXPDP_DUMPDIR 4 5G 7 /ora_share_nfs/backup/shwm
/ora_share_nfs/scripts/expdp_full_audit_and_wallet.ksh shsub /opt/app/oracle/product/11.2.0/11.2.0.4 EXPDP_DUMPDIR 4 5G 7 /ora_share_nfs/hmaissubdb01/shsub
/ora_share_nfs/scripts/expdp_full_audit_and_wallet.ksh shwm /opt/app/oracle/product/11.2.0/11.2.0.4 EXPDP_DUMPDIR 4 5G 7 /ora_share_nfs/hmaissubdb01/shwm
oracle@shsub:/opt/oradiag/diag/rdbms/shsub/shsub/trace>cat /ora_share_nfs/scripts/expdp_full.ksh
#!/bin/ksh
#set -x
# Usage:
# /export/home/oracle/scripts/bin/expdp_full.ksh
# parameters $ORACLE_SID $ORACLE_HOME EXPDP_DIR NO_PARALLEL FILESIZE RETENTION DEST_DIR
#
# Sample
# /export/home/oracle/scripts/bin/expdp_full.ksh dktms /opt/app/oracle/product/11.2.0/11.2.0.3 EXPDP_DUMPDIR 4 5G 7 /ora_share_nfs/kmaistmsdb/dktms
# /export/home/oracle/scripts/bin/expdp_full.ksh dktms2 /opt/app/oracle/product/11.2.0/11.2.0.3 EXPDP_DUMPDIR 4 5G 7 /ora_share_nfs/kmaistmsdb/dktms2
# /export/home/oracle/scripts/bin/expdp_full.ksh dktms3 /opt/app/oracle/product/11.2.0/11.2.0.3 EXPDP_DUMPDIR 4 5G 7 /ora_share_nfs/kmaistmsdb/dktms3
# /export/home/oracle/scripts/bin/expdp_full.ksh dktms4 /opt/app/oracle/product/11.2.0/11.2.0.3 EXPDP_DUMPDIR 4 5G 7 /ora_share_nfs/kmaistmsdb/dktms4
# /export/home/oracle/scripts/bin/expdp_full.ksh dktms /opt/app/oracle/product/11.2.0/11.2.0.3 EXPDP_DUMPDIR 4 5G 7 /ora_share_nfs/kmaistmsdb/sktms
# /export/home/oracle/scripts/bin/expdp_full.ksh dktms3 /opt/app/oracle/product/11.2.0/11.2.0.3 EXPDP_DUMPDIR 4 5G 7 /ora_share_nfs/kmaistmsdb/sktms3
# /export/home/oracle/scripts/bin/expdp_full.ksh dktms4 /opt/app/oracle/product/11.2.0/11.2.0.3 EXPDP_DUMPDIR 4 5G 7 /ora_share_nfs/kmaistmsdb/sktms4
#
. ~oracle/.profile
# Script to do an export datapump of database, compress it, and delete dumps older than 7 days
# Variables go here. Change according to environment and needs
RUN_DATE=`date "+%m%d%Y_%H%M%S"`
export ORACLE_SID=$1
export ORACLE_HOME=$2
export EXPDP_DIR=$3
export NO_PARALLEL=$4
export FILESIZE=$5
export RETENTION=$6
export DEST_DIR=$7
export HOSTNAME=`hostname`
export LOG_FILE_01=/export/home/oracle/scripts/logs/${ORACLE_SID}_expdp_full_01.log
export LOG_FILE_02=/export/home/oracle/scripts/logs/${ORACLE_SID}_expdp_full_02.log
echo "parameters: " $ORACLE_SID $ORACLE_HOME $EXPDP_DIR $NO_PARALLEL $FILESIZE $RETENTION $DEST_DIR
MAIL_TO='his-dba-alerts@hke.local'
# End of variables
# Remove old dmp files (generated by manually or from previous failed job)
ls $DEST_DIR/*full*dmp
ls $DEST_DIR/*full*dmp > $LOG_FILE_01
#grep "No such file or directory" $LOG_FILE_01 > $LOG_FILE_02
#grep "dmp" $LOG_FILE_01 > $LOG_FILE_02
if [ -s $LOG_FILE_01 ];then
rm $DEST_DIR/*full*dmp
fi
if [ $NO_PARALLEL -eq '0' ]; then
# expdp \"\/ as sysdba\" full=y directory=${EXPDP_DIR} dumpfile=${ORACLE_SID}_full_${RUN_DATE}_%U.dmp filesize=${FILESIZE} logfile=${ORACLE_SID}_full_${RUN_DATE}.log compression=all EXCLUDE=STATISTICS
$ORACLE_HOME/bin/expdp \"\/ as sysdba\" full=y directory=${EXPDP_DIR} dumpfile=${ORACLE_SID}_full_${RUN_DATE}_%U.dmp filesize=${FILESIZE} logfile=${ORACLE_SID}_full_${RUN_DATE}.log EXCLUDE=STATISTICS
else
# expdp \"\/ as sysdba\" full=y directory=${EXPDP_DIR} dumpfile=${ORACLE_SID}_full_${RUN_DATE}_%U.dmp parallel=${NO_PARALLEL} filesize=${FILESIZE} logfile=${ORACLE_SID}_full_${RUN_DATE}.log compression=all EXCLUDE=STATISTICS
$ORACLE_HOME/bin/expdp \"\/ as sysdba\" full=y directory=${EXPDP_DIR} dumpfile=${ORACLE_SID}_full_${RUN_DATE}_%U.dmp parallel=${NO_PARALLEL} filesize=${FILESIZE} logfile=${ORACLE_SID}_full_${RUN_DATE}.log EXCLUDE=STATISTICS
fi
EXPDP_STATUS=$?
echo
echo "EXPDP_STATUS: " $EXPDP_STATUS
echo
if [ ${EXPDP_STATUS} -eq 0 ]; then
sqlplus / as sysdba <<EOF
-- Backup spfile by create pfile from spfile.
create pfile='${DEST_DIR}/init${ORACLE_SID}_${RUN_DATE}.ora' FROM spfile;
EOF
# Archive and compress backup
cd ${DEST_DIR}
tar cEvf ${ORACLE_SID}_full_${RUN_DATE}.tar ${DEST_DIR}/${ORACLE_SID}_full_${RUN_DATE}_*.dmp
TAR_STATUS=$?
echo
echo "TAR_STATUS: " $TAR_STATUS
echo
if [ ${TAR_STATUS} -eq 0 ]; then
gzip ${ORACLE_SID}_full_${RUN_DATE}.tar
GZIP_STATUS=$?
echo
echo "GZIP_STATUS: " $GZIP_STATUS
echo
if [ ${GZIP_STATUS} -eq 0 ]; then
#bzip2 ${ORACLE_SID}_full_${RUN_DATE}.tar
#BZIP2_STATUS=$?
#if [ ${BZIP2_STATUS} -eq 0 ]; then
#Delete original dumps
rm ${DEST_DIR}/${ORACLE_SID}_full_${RUN_DATE}_*.dmp
find ${DEST_DIR}/${ORACLE_SID}_full_* -mtime +${RETENTION} -exec rm -f {} \;
find ${DEST_DIR}/init${ORACLE_SID}_*.ora -mtime +${RETENTION} -exec rm -f {} \;
echo "${ORACLE_SID}@$HOSTNAME: full export succeeded." | mailx -s "${ORACLE_SID}@$HOSTNAME: Backup by expdp Notification: SUCCESS" ${MAIL_TO}
else
#Do a cleanup
rm ${DEST_DIR}/${ORACLE_SID}_full_${RUN_DATE}_*.dmp
rm ${DEST_DIR}/${ORACLE_SID}_full_${RUN_DATE}.tar
echo "${ORACLE_SID}@$HOSTNAME: full export failed by gzip command." | mailx -s "${ORACLE_SID}@$HOSTNAME: Backup by expdp Notification: FAILED" ${MAIL_TO}
#echo "${ORACLE_SID}@$HOSTNAME: full export failed by gzip command." | mailx -s "${ORACLE_SID}@$HOSTNAME: Backup by expdp Notification: FAILED" ${MAIL_TO} < $DEST_DIR/${ORACLE_SID}_full_${RUN_DATE}.log
fi
else
#Do a cleanup
rm ${DEST_DIR}/${ORACLE_SID}_full_${RUN_DATE}_*.dmp
rm ${DEST_DIR}/${ORACLE_SID}_full_${RUN_DATE}.tar
rm ${DEST_DIR}/${ORACLE_SID}_full_${RUN_DATE}.tar.gz
echo "${ORACLE_SID}@$HOSTNAME: full export failed by tar command." | mailx -s "${ORACLE_SID}@$HOSTNAME: Backup by expdp Notification: FAILED" ${MAIL_TO}
#echo "${ORACLE_SID}@$HOSTNAME: full export failed by tar command." | mailx -s "${ORACLE_SID}@$HOSTNAME: Backup by expdp Notification: FAILED" ${MAIL_TO} < $DEST_DIR/${ORACLE_SID}_full_${RUN_DATE}.log
fi
else
echo "${ORACLE_SID}@$HOSTNAME: full export failed." | mailx -s "${ORACLE_SID}@$HOSTNAME: Backup by expdp Notification: FAILED" ${MAIL_TO}
#echo "${ORACLE_SID}@$HOSTNAME: full export failed." | mailx -s "${ORACLE_SID}@$HOSTNAME: Backup by expdp Notification: FAILED" ${MAIL_TO} < $DEST_DIR/${ORACLE_SID}_full_${RUN_DATE}.log
fi
No comments:
Post a Comment