oracle自动备份linux

#!/bin/bash
export ORACLE_SID=dgdb
export ORACLE_BASE=/u01/app/oracle/product
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export ORACLE_ADMIN=/u01/app/oracle/admin
export ORACLE_HOME_LISTNER=$ORACLE_HOME
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/jlib
export JAVA_HOME=$ORACLE_HOME/jdk
export ORA_NLS10=$ORACLE_HOME/nls/data
export PATH=$ORACLE_HOME/bin:/usr/bin:/usr/sbin:/usr/local/sbin:/usr/lib:$JAVA_HOME/bin:$PATH
export LANG=AMRICAN
export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"
export BAKUPTIME=`date +%Y%m%d`
export DATA_DIR=/u01/app/oracle/admin/dgdb/dpdump
export ORACLE_version=11.2.0.4.0
cd $DATA_DIR         
# export data
expdp activi/activi@dgdb schemas=gj_activi dumpfile=activi_$BAKUPTIME.dmp version=$ORACLE_version
expdp inst/inst@dgdb schemas=inst dumpfile=inst_$BAKUPTIME.dmp version=$ORACLE_version
expdp model/model@dgdb schemas=model dumpfile=model_$BAKUPTIME.dmp version=$ORACLE_version

#compress data
tar czf $DATA_DIR/XM_$BAKUPTIME.tar.gz *_$BAKUPTIME.dmp
# copy data to remote svr
/usr/bin/sshpass -p oracle scp $DATA_DIR/XM_$BAKUPTIME.tar.gz oracle@IP:/u01/app/oracle/admin/dgdb/dpdump
#delete source data
rm -f $DATA_DIR/*_$BAKUPTIME.dmp
# del tar package before 4 days
twoweekago=$(date -d "4 days ago" +'%Y%m%d')
rm -f $DATA_DIR/XM_${twoweekago}.tar.gz

安装sshpass

cd /opt
wget http://downloads.sourceforge.net/project/sshpass/sshpass/1.06/sshpass-1.06.tar.gz
tar xf sshpass-1.06.tar.gz 
cd sshpass-1.06
./configure --prefix=/usr/local/
make && make install
cp /usr/local/bin/sshpass /usr/bin/

上一篇:sshpass实现批量基于ssh的key部署


下一篇:ssh参数中无密码选项-解决方式