备份infobright数据库

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#!/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}"