备份infobright数据库

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

#!/bin/bash
#Author Castle Liu
#Date	2014-05-28
_BACKUP_DIR='/data/backup/IB/'
_BACKUP_NAME=IB`date +"%Y%m%d%H"`
_WORKING_DIR=${_BACKUP_DIR}${_BACKUP_NAME}
_TMP_F='/tmp/backUpInforBright'
_DBUSER=''
_DBPASSWD=''
_DB='PE_DW'
_HEADER='date +"%F %T"'
_QUERY_CMD='mysql-ib'
_BACKUP_CMD='/usr/local/infobright/bin/mysqldump'

####functions###
#help
#function used to print help info.
help() {
        cat <<EOF
        -d      how many days ago's file you want to delete on backup_dir.,default 7;
        -h      print help information.
EOF
}

#parse_args
#function to parse paremeters.
#do pass in the args from shell,for example:parse_args $*
parse_args(){
        while getopts "ht:d:s:" arg
        do
                case ${arg} in
                        h)
                                help
                                exit 0
                                ;;
                        d)
                                export _DAY=${OPTARG}
                                ;;
                        ?)
                                echo "Unknown argument,exit..."
                                exit 1
                                ;;
                        esac
        done
}

#backUpTable
#backup the table
backUpTable(){
	tableName=$1
	echo "`eval ${_HEADER}` Start backing up table ${tableName}..."|tee -a ${_TMP_F}
	${_BACKUP_CMD} -u${_DBUSER} -p${_DBPASSWD} --lock-tables=false ${_DB} ${tableName} > ${_WORKING_DIR}/${tableName}.sql|tee -a ${_TMP_F}
	fileSize=`ls -lh  ${_WORKING_DIR}/${tableName}.sql|awk '{print $5}'`
	echo "`eval ${_HEADER}` End backing up table:${tableName},Size:${fileSize}."|tee -a ${_TMP_F}
}



###main###
echo "`eval ${_HEADER}` InforBright backUp begin..."|tee ${_TMP_F}
parse_args $*

#Delete files on backup dir.
_DAY=${_DAY:-7}
#find ${_BACKUP_DIR} -mtime 7 -exec rm -rf {} \;
#echo ${_DAY}

#backup inforbright
mkdir -p ${_WORKING_DIR}
${_QUERY_CMD} -u${_DBUSER} -p${_DBPASSWD} -e "select table_name from information_schema.tables where table_schema='PE_DW';"|awk 'NR>2{print}' > running.tmp
cat ${_TMP_F}.tmp|while read table
do
	if [[ ${table} != "EOF" ]];then
		#echo ${table}
		backUpTable ${table}
	fi
done

cd ${_BACKUP_DIR}
tar -czvf ${_BACKUP_NAME}.tar.gz ${_BACKUP_NAME}
rm -rf ${_BACKUP_NAME}
echo "`eval ${_HEADER}` InforBright backUp end."|tee -a ${_TMP_F}

#send a email to acknowage backup info
pmail "***ALIYUN_INFORBRIGHT_BACKUP_REPORT***" "${_TMP_F}"

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

相关文章

系ubuntu 下面打开终端输入:sudo apt-get install sendmail...
依家我有1个软件goagent目录(大家懂得) 放在/home/gateman/...
其实我想讲的是 cp -L关于-L参数的解释:-L, --dereferenc...
原地址:http://www.rjgc.net/control/content/content.php?...
chroot,即 change root directory (更改 root 目录)。在 li...
简单解析下, stdin就是标准输入, stdout就是标准。举个例子...