前端时间有个朋友需要升级vos4.0-6.0,需要我帮忙把数据库备份下所以才有一下脚本

#!/usr/bin/env bash
#传参
bk_directory="/"

#调用函数库
[ -f /etc/init.d/functions ] && source /etc/init.d/functions
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
source /etc/profile

#Require root to run this script.
[ $(id -u) -gt 0 ] && echo "请用root用户执行此脚本!" && exit 1

database="vos3000"
dbuser="root"
dbpasswd="xiaofan@1"
options=""
KEEP_DATE=$(date "+%Y%m")
 
#定义排除表的数组
#不保留话单
ignoreTableArray=`mysql -u${dbuser} -p${dbpasswd} -D ${database} -Bse "SHOW TABLES LIKE 'e_cdr_%'" | grep -v e_cdr_${KEEP_DATE}`
#保留1个月话单
#ignoreTableArray=`mysql -u${dbuser} -p${dbpasswd} -D ${database} -Bse "SHOW TABLES LIKE 'e_cdr_%'" | grep -v e_cdr_${KEEP_DATE}`
 
#实现排除函数
function mysql_ignoreTable(){
        for table in  ${ignoreTableArray[@]}
        do
                s="--ignore-table="${database}.${table}" "
                options=${options}${s}
        done
        #${options}拼接排除的表
        echo ${options}
        mysqldump -u${dbuser} -p${dbpasswd} ${database} ${options} --skip-lock-tables > ${database}.sql
}
 
mysql_ignoreTable