Mysql迁移数据前后数据量对比

Mysql迁移数据前后数据量对比脚本,日常记录备份

#!/bin/sh
export MYSQL_PWD='root'
FILE=list.txt
## eg: list.txt 长成下面这样,把excel文件里的这两列直接拷贝进去
<<list.txt
report	d1
report	d2
report	d3
report	d4
... ...
list.txt

#第一个数据库的连接属性
DB01_HOST=10.0.0.1
DB01_PORT=3306
DB01_USER=root
SRC_FILE=src.txt

#第二个数据库的连接属性
DB02_HOST=10.0.0.2
DB02_PORT=3306
DB02_USER=root
DEST_FILE=dest.txt


function readFileContent1(){
    counter=0
    while read -a line
    do
    counter=$((counter+1)) 
    #echo ${line[0]}
    #echo ${line[1]}
    printf ${line[0]} && printf " ${line[1]} " && mysql -h ${DB01_HOST} -u ${DB01_USER}  ${line[0]} -s -e "select count(*) from ${line[1]}" 
    done<${1}
    echo ${counter}
}

function readFileContent2(){
    counter=0
    while read -a line
    do
    counter=$((counter+1)) 
    printf ${line[0]} && printf " ${line[1]} " && mysql -h ${DB02_HOST} -u ${DB02_USER}  ${line[0]} -s -e "select count(*) from ${line[1]}" 
    done<${1}
    echo ${counter}
}

function main(){
printf "file number: " && wc -l ${FILE}
echo "======= start src db count ========"
time readFileContent1 "${FILE}" > ${SRC_FILE} 
printf "src number: " && tail -n1 ${SRC_FILE} 
echo "======= start dest db count ========"
time readFileContent2 "${FILE}" > ${DEST_FILE}
printf "dest number: " && tail -n1 ${DEST_FILE} 
echo "======= start diff file ========"
diff ${SRC_FILE} ${DEST_FILE}
if [ $? -eq 0 ];then
    echo "file all same!"
else
    echo "file have different!!!"
fi
}

main
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值