vim backup.sh
#!/bin/bash
kdb_home="/opt/Kingbase/ES/V8/Server"
kdbback_dest="/opt/kingbaseback"
kdb_user="system"
kdb_pass="123456"
kdb_port="54321"
kdb_host="1.1.1.1"
kdb_list="TEST"
keep_time="7"
date=$(date '+%Y%m%d%H')
kdbback_final="${kdbback_dest}/kdbback_final"
LD_LIBRARY_PATH="${kdb_home}/unixodbc/lib:${kdb_home}/lib:${kdb_home}/bin"
[ -d ${kdbback_dest} ] || mkdir -p ${kdbback_dest}
[ -d ${kdbback_final} ] || mkdir -p ${kdbback_final}
cd ${kdbback_dest}
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH
for db in `echo $kdb_list | sed 's/,/ /g'`; do
[ -d ${db} ] || mkdir -p ${db}
cd ${db}
${kdb_home}/bin/ksql "host=${kdb_host} port=${kdb_port} dbname=${db} user=${kdb_user} password=${kdb_pass}" -c "select now();"> /dev/null 2>&1
if [ $? -ne 0 ] ;then
echo "${date} 对不起,检测到kingbase数据库未启动,请先启动" >> backup_${db}_${date}.log
mv backup_${db}_${date}.log ${kdbback_final}
exit 1
else
echo "${date} kingbase数据库正常运行中,${db}库正常" >> backup_${db}_${date}.log
fi
${kdb_home}/bin/sys_dump "host=${kdb_host} port=${kdb_port} dbname=${db} user=${kdb_user} password=${kdb_pass}" -F c -f ${db}_${date}.dmp>>backup_${db}_${date}.log 2>&1
if [ $? -eq 0 ] ;then
tar zcvf ${db}_${date}.tar.gz ${db}_${date}.dmp*
if [ $? -eq 0 ] ;then
rm -f ${db}_${date}.dmp*
else
mv ${db}_${date}.dmp* ${kdbback_final}
fi
find . -mtime +${keep_time} -name ${db}'_*' | xargs -I {} rm {}
else
rm -f ${db}_${date}.dmp*
fi
tar zcvf backup_log_${db}_${date}.tar.gz backup_${db}_${date}.log
if [ $? -eq 0 ] ;then
rm -f backup_${db}_${date}.log
else
mv backup_${db}_${date}.log ${kdbback_final}
fi
find . -mtime +${keep_time} -name backup_log_${db}'_*' | xargs -I {} rm {}
cd ${kdbback_dest}
done
exit 0
~
~
非交互式数据库还原
PGPASSWORD=123456 sys_restore -h127.0.0.1 -Usystem -d abc xxx.dmp //非交互式还原数据库
非交互式数据库登录
ksql "host=1.1.1.1 post=54321 user=system dbname=test password=123456" //R6非交互式的方式登录数据库
|