恢复--系统配置表的shell


恢复--系统配置表的shell
 
配置用户名密码文件report.ini
user1/pswd1@dbname1
user2/pswd2@dbname2
配置系统表文件configtable.ini
user1.table1
user2.table2
user3.table3
 
脚本backup.sh
一次读取配置文件,并做验证,如果密码错误则进行修改,将每个用户的配置表进行导入
备份文件包的名称由用户输入
 
#!/usr/bin/ksh
 
dmpfilepath='./'
connfile=report.ini
configtable=configtable.ini
DT=$1
while [ ! -r ${dmpfilepath}${DT}.*.dmp ]
do
    if [ -n "$DT" ]
    then
        ll -rt ${dmpfilepath}*.dmp | tail -20
    fi
    echo "Please input dmp's basename:\c"
    read DT
done
 
 
#检查连接串正确性
checkconn()
{
if [ "$#" -ne 1 ]
then
echo "-1"
exit
fi
 
 
    VALUE=`sqlplus -s /nolog <<EOF
    set head off
    conn $dbconn
    select 1 from dual;
    exit
    EOF`
    echo $VALUE
}
#将密码写入配置文件
modipswd()
{
if [ "$#" -ne 2 ]
then
echo "-1"
exit
fi
 
 
    user=`echo $1 | cut -d/ -f1`
    dbnm=`echo $1 | cut -d@ -f2`
    newconn=`echo $dbconn | sed 's/\//\\\\\//g`
    cat $2 | sed "/^$user\/.*@$dbnm/s/^.*$/$newconn/g" >temp$$
    mv temp$$ $connfile
}
 
 
#读取配置文件
for dbuser in `cat $configtable | sed -e "s/^ *//g" -e "s/\..*//g" | sort | uniq `
do
    v_time=0
    dbconn=`cat $connfile | grep "^ *$dbuser/"`
    checkconn_flg=$(checkconn $dbconn)
    while [ "$checkconn_flg" != "1" -a $v_time -lt 3 ]
    do
        v_time=`expr $v_time + 1`
        stty -echo
        echo $dbuser'@'`echo $dbconn | cut -d@ -f2` password is error," please input new password:\c"
        read newpswd
        echo ''
        dbconn=$dbuser'/'$newpswd'@'`echo $dbconn | cut -d@ -f2`
        stty echo
        checkconn_flg=$(checkconn $dbconn)
        if [ "$checkconn_flg" = "1" ]
        then
            modipswd $dbconn $connfile
            break
        fi
    done
    alltab=''
    #读取配置表
    cat $configtable | grep "^ *$dbuser." |
    while read dbtab
    do
        alltab=$alltab,`echo $dbtab | cut -d. -f2`
        VALUE=`sqlplus -s /nolog <<EOF
        set head off
        conn $dbconn
        truncate table $dbtab;
        exit
        EOF`
    done
    alltab=`echo $alltab | cut -c2-`
    if [ -n "$alltab" ]
    then
        echo :$alltab:
        imp $dbconn file=${dmpfilepath}${DT}.$dbuser.dmp ignore=y
    fi
 
done
 

相关内容

    暂无相关文章