expdp 邏輯備份指令碼

abin1703發表於2018-05-21
#!/bin/bash
##########defined variable############
current_date=`date +%Y%m%d`
old_date=`date -d "3 day ago" +%Y%m%d`
#########create directory##################
if [ ! -d "/zhjs_bakup/$current_date" ];then
mkdir -p /zhjs_bakup/$current_date
else
echo "$current_date directory exits"
fi
##############create    Logical directory############


sqlplus sys/oracle@cntjs as sysdba <<EOF
drop directory expdp;
create directory expdp as '/zhjs_bakup/${current_date}';
grant read,write on directory expdp to public;
set lines 200
col OWNER for a10
col DIRECTORY_NAME for a20
col DIRECTORY_PATH for a60
select OWNER,DIRECTORY_NAME,DIRECTORY_PATH from dba_directories where DIRECTORY_NAME='EXPDP';
EOF


##############source envionment variables################
source .bash_profile
######################expdp for backup###################
expdp \'sys/oracle@cntjs as sysdba\' directory=expdp dumpfile=expdp_cntjs_${current_date}_%U.dmp full=y parallel=10 cluster=no COMPRESSION=all exclude=STATISTICS logfile=expdp_cntjs_${current_date}.log
#####################backup for status###################
if [ $? == 0 ];then
echo -e "\033[32m ******** executed ${current_date} successfully ***********\033[0m"
else
echo -e "\033[31m ******** executed ${current_date} failed  ****************\033[0m"
fi


####################delete 3 day befire backup ########################
ls -l /zhjs_bakup/$old_date
rm -rf /zhjs_bakup/$old_date


if [ $? == 0 ];then
echo -e "\033[32m ########delete backup $old_date  successfully #############\033[0m"
else
echo -e "\033[31m ########delete backup $old_date  failed ###########\033[0m"
fi

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30345407/viewspace-2154834/,如需轉載,請註明出處,否則將追究法律責任。

相關文章