備份指令碼--紀錄

realji發表於2007-01-28

vi bak.sh
-------
#設定oracle 的環境變數
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

#export LD_ASSUME_KERNEL=2.4.1
export ORACLE_BASE=/data/oracle
export ORACLE_HOME=/data/oracle/OraHome
export ORACLE_SID=sms
export ORACLE_TERM=xterm
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH
export PATH=$PATH:$ORACLE_HOME/bin
CLASSAPTH=$CLASSPATH:$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
export CLASSPATH
unset USERNAME
export PATH
unset USERNAME

export "NLS_LANG=SIMPLIFIED CHINESE_CHINA.ZHS16GBK"


#make diretory for everyday's backup
rq=`date +%Y-%m-%d-%H%M`
a=`date +%d` #day
b=`date +%m` #month
c=`date +%Y` #year,like 2006
let d=a-7
let e=b-1
if [ $d < 0 ] && [ $e = 0 ] #if now it is Jan ,and date less then 7th
then
g=$d+30 #day
h=12 #month
c=$c-1 #year
else
g=$d #day
h=$b #month
fi
rq_del=$c-$h-$g
rm -f -r /data/orabak/ivr/$rq_del*
#echo $rq_del
cd /data/orabak/ivr
mkdir $rq
#export data
#move data to backup directory,then delete reduncdent.
cp /data/orabak/ivr/$rq/* /data/orabak/ivr/
tar zcvf bak.tar.gz /data/orabak/ivr/*.dmp *.log
rm -f /data/orabak/ivr/*.dmp *.log

cd /data/orabak/ivr
mkdir $rq
#export data
exp usr/pwd OWNER=user BUFFER=2048000 STATISTICS=NONE FILE=/data/orabak/ivr/$rq/ivr_$rq.dmp LOG=/data/orabak/ivr/$rq/backup_$rq.log
#move data to backup directory,then delete reduncdent.
cp /data/orabak/ivr/$rq/* /data/orabak/ivr/
tar zcvf bak.tar.gz /data/orabak/ivr/*.dmp *.log
rm -f /data/orabak/ivr/*.dmp *.log
rm -f -r /data/orabak/ivr/$rq_del*
#time sync
/usr/sbin/ntpdate 210.72.145.44

[@more@]

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

相關文章