EXP的備份指令碼

BTxigua發表於2007-08-18

#!/bin/sh
#Set the oracle environment variables base your actual vlaue
ORACLE_SID=ORACLE2
export ORACLE_SID
#BAK_PATH is a path that store your exp file
BAK_PATH=/home/guest/wangyushen/bak

#LOG_FILE is a file that recorde the results of export
LOG_FILE="$BAK_PATH"/`date -u +%Y%m%d`_brief.log
#Define the exp user
USER=dxh
#Define the exp user's password
PASSWD=dxh
#Determine the current user name
CUSER=`id |cut -d"(" -f2 | cut -d ")" -f1` # `who am i | cut -d " " -f1` cuser=whoami
#Define the retention days of your backup file
DAYS=3

[@more@]

#******************************************************************
#It is unnecessary to edit the the below text in normal condition.*
#******************************************************************

echo "The start time is: "`date` >> $LOG_FILE
echo >> $LOG_FILE
rm_oldfile(){ find /home/guest/dxhibm/test/ -type f -mtime +1 -exec rm {} ;}
rm_oldfile>>`date -u +%Y%m%d`_brief.log

rm_oldfile(){
find $BAK_PATH -mtime +$DAYS -exec rm {} ;
}
#Remove the expire backup file
rm_oldfile>>$LOG_FILE

#Define the backup file name
BAK_FILE=`date -u +%Y%m%d`_full.dmp
#Define the backup log file name
BAK_LOG=`date -u +%Y%m%d`_full.log
#Define your backup command
CMD_STR="
exp $USER/$PASSWD@$ORACLE_SID tables=t_dxh_area,t_dxh_config,t_dxh_dxhhuser_0,t_dxh_dxhhuser_1,t_dxh_dxhhuser_2,t_dxh_dxhhuser_3,t_dxh_dxhhuser_4,t_dxh_dxhhuser_5,t_dxh_dxhhuser_6,t_dxh_dxhhuser_7,t_dxh_dxhhuser_8,t_dxh_dxhhuser_9,t_dxh_dxhuser_0,t_dxh_dxhuser_1,t_dxh_dxhuser_2,t_dxh_dxhuser_3,t_dxh_dxhuser_4,t_dxh_dxhuser_5,t_dxh_dxhuser_6,t_dxh_dxhuser_7,t_dxh_dxhuser_8,t_dxh_dxhuser_9,t_dxh_feesetup,t_dxh_localheadno,t_dxh_mobile,t_dxh_operator,t_dxh_redblacklist file=$BAK_PATH/$BAK_FILE log=$BAK_PATH/$BAK_LOG grants=y
"

#Begin backup
echo "Backup is started" >>$LOG_FILE
echo "......">>$LOG_FILE
if [ "$CUSER" = "root" ]
then
su - oracle -c "$CMD_STR" >> $LOG_FILE
RSTAT=$?
else
/usr/bin/sh -c "$CMD_STR" >> $LOG_FILE
RSTAT=$?
fi
if [ "$RSTAT" = "0" ]
then
echo "Backup to Hard disk is ended successful!" >> $LOG_FILE
else
echo "Notice! Backup hard disk is ended unsuccessful!">> $LOG_FILE
fi
echo >>$LOG_FILE
echo "Backup to Hard disk End time is: "`date`>>$LOG_FILE
compress -f $BAK_PATH/$BAK_FILE >> $LOG_FILE
if [ $? -eq 0 ]
then
echo "compress file is ended successful!" >> $LOG_FILE
echo >>$LOG_FILE
else
echo "Notice!!compress file is ended unsuccessful!" >> $LOG_FILE
echo "Please contact with Metarnet Engineer"
fi
echo "Backup to Tape End time is: "`date`>>$LOG_FILE

#backup file to oracle1
remote_path="/home/guest/wangys"
host="10.33.19.186"
username="root"
password="jsyddxh!"

cd $BAK_PATH
ftp -n -i $host<user $username $password
prompt
bi
cd $remote_path
put "$BAK_FILE".Z
bye
!FTPEND

if [ $? -eq 0 ]
then
echo "Put file to oracle1 is ended successful!" >> $LOG_FILE
echo >>$LOG_FILE
else
echo "Notice!!Put file to oracle1 is ended unsuccessful!" >> $LOG_FILE
echo "Please contact with Metarnet Engineer"
fi

rm "$BAK_FILE".Z
echo "All is done! Time is:" `date`>>$LOG_FILE

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

相關文章