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