备份--系统配置表的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
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 <<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`
done
alltab=`echo $alltab | cut -c2-`
if [ -n "$alltab" ]
then
echo :$alltab:
exp $dbconn file=${dmpfilepath}${DT}.$dbuser.dmp tables=/($alltab/)
fi
done