參考 How to Monitor Your MySQL Database Restore Progress

方式一

# 當還原時

mysql crossdb < crossdb.sql

# 取得 pid (ps axu | grep crossdb)

pid="123456789"
while true; do
    if [ -f /proc/${pid}/io ]; then
        bytes_progress=$(cat /proc/${pid}/io | awk '/^rchar/ {print $2}')
        bytes_total=$(cat /root/backup.sql | wc -c)
        progress=$(awk "BEGIN {printf "%.2f", ((100 * $bytes_progress)/$bytes_total)}")
        echo "Progress: $progress%"
        sleep 5;
        continue;
    else
        break;
    fi
done

# 結果

Progress: 37.36%
Progress: 39.91%
Progress: 42.05%
Progress: 44.56%
Progress: 46.99%

方式二

# 這個簡單多了

yum install pv -y
pv crossdb.sql | mysql crossdb