频道栏目
IT货架 > > 正文
backup script
网友分享于:Jan 1, 1970 8:00:00 AM    来源: IT货架   

标签:style   blog   color   name   代码   for   

#!/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

标签:style   blog   color   name   代码   for   

广告服务联系QQ:1134687142 | 网站地图

版权所有: IT货架- 内容来自互联网,仅供用于技术学习,请遵循相关法律法规. 京ICP备11030978号-1