Chinaunix首页 | 论坛 | 博客
  • 博客访问: 116375
  • 博文数量: 24
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 0
  • 用 户 组: 普通用户
  • 注册时间: 2016-11-22 14:58
个人简介

坚持,做最好的自己

文章分类

全部博文(24)

文章存档

2015年(2)

2014年(9)

2013年(13)

我的朋友

分类: 其他UNIX

2013-04-02 19:02:00

配置用户名密码文件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
if [ "$#" -eq 0 ]
then
    DT=`date +%Y%m%d%H%M%S`
    date
else
    DT=$1
fi


#检查连接串正确性
checkconn()
{
if [ "$#" -ne 1 ]
then
echo "-1"
exit
fi


    VALUE=`sqlplus -s /nolog <     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`
    done
    alltab=`echo $alltab | cut -c2-`
    if [ -n "$alltab" ]
    then
        echo :$alltab:
        exp $dbconn file=${dmpfilepath}${DT}.$dbuser.dmp tables=\($alltab\)
    fi


done

阅读(1772) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~