首页 > 其他 > 详细

backup script

时间:2014-06-28 19:55:20      阅读:356      评论:0      收藏:0      [点我收藏+]
#!/bin/bash
#####################################################
#    export the whole database use exp utility.     #
#####################################################

#########load db profile#############################
. ~/profile/c21upg10.profile

#########set nls_lang################################
db_nls_value=`sqlplus -s / as sysdba <<EOF
select userenv(language) from dual;
EXIT
EOF`
NLS_LANG=`(echo $db_nls_value | cut -d  -f3)`
export NLS_LANG


##########exp########################################
file_name="${ORACLE_SID}_full_`date ‘+%y%m%d‘`.dmp"
log_name="${ORACLE_SID}_imp_`date ‘+%y%m%d‘`.log"
backup_location=/u01/db_backup
exp \/ as sysdba\‘ file=$backup_location/$ORACLE_SID/$file_name log=$backup_location/$ORACLE_SID/$log_name full=y

##########compress and delete obsoleteness###########
gzip $backup_location/$ORACLE_SID/*.dmp

 

 

 

后来加了一段删除冗余代码。 这段代码中要记住的有几点

1. 设置日期

date -d "-1 week" +%y%m%d
date -d "-1 day" +%y%m%d

2. 判断shell命令执行成功与否

command ; flag=$?

if [ $flag -eq 0 ]


cur_bak=$backup_location/$ORACLE_SID/${ORACLE_SID}_full_`date +%y%m%d`.dmp.gz
cur_bak_7=$backup_location/$ORACLE_SID/${ORACLE_SID}_full_`date -d "-1 week" +%y%m%d`.dmp.gz
cur_bak_14=$backup_location/$ORACLE_SID/${ORACLE_SID}_full_`date -d "-2 week" +%y%m%d`.dmp.gz
cur_log=$backup_location/$ORACLE_SID/${ORACLE_SID}_imp_`date +%y%m%d`.log
cur_log_7=$backup_location/$ORACLE_SID/${ORACLE_SID}_imp_`date -d "-1 week" +%y%m%d`.log
cur_log_14=$backup_location/$ORACLE_SID/${ORACLE_SID}_imp_`date -d "-4 week" +%y%m%d`.log
    
if [ -a $cur_bak ] && [ -a $cur_bak_7 ] && [ -a $cur_bak_14 ] ;
then
    grep "Export terminated successfully without warnings" $cur_log >/dev/null 2>&1 ; flag1=$?
    grep "Export terminated successfully without warnings" $cur_log_7 >/dev/null 2>&1 ; flag2=$?
    grep "Export terminated successfully without warnings" $cur_log_14>/dev/null 2>&1 ; flag3=$?
    if [ $flag1 -eq 0 ] && [ $flag2 -eq 0 ] && [ $flag3 -eq 0 ] ;
    then
        mkdir $backup_location/$ORACLE_SID/temp; flag1=$?
        mv $cur_bak $backup_location/$ORACLE_SID/temp ;flag2=$?
        mv $cur_bak_7 $backup_location/$ORACLE_SID/temp ;flag3=$?
        mv $cur_bak_14 $backup_location/$ORACLE_SID/temp ;flag4=$?
        mv $cur_log $backup_location/$ORACLE_SID/temp ;flag5=$?
        mv $cur_log_7 $backup_location/$ORACLE_SID/temp ;flag6=$?
        mv $cur_log_14 $backup_location/$ORACLE_SID/temp ;flag7=$?
        if [ $flag1 -eq 0 ] && [ $flag2 -eq 0 ] && [ $flag3 -eq 0 ] && [ $flag4 -eq 0 ] && [ $flag5 -eq 0 ] && [ $flag6 -eq 0 ]  && [ $flag7 -eq 0 ] ;
        then
            rm $backup_location/$ORACLE_SID/*.gz ; flag1=$?
            rm $backup_location/$ORACLE_SID/*.log; flag2=$?
            mv $backup_location/$ORACLE_SID/temp/* $backup_location/$ORACLE_SID/; flag3=$?
            rm -r $backup_location/$ORACLE_SID/temp/; flag4=$?
            if [ $flag1 -eq 1 ] || [ $flag2 -eq 0 ] || [ $flag3 -eq 0 ] || [ $flag4 -eq 0 ];then
                echo "send email for here0"
            fi
        fi
    fi
else
    echo "send email for here1"
fi

 

backup script,布布扣,bubuko.com

backup script

原文:http://www.cnblogs.com/kramer/p/3794692.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!