The mysqldump-command doesn't really support viewing the progress of exporting a database. I guess it's because it gives overhead, and it's frankly quite difficult to generate a fluid progressbar.

Therefore I've created a simple script to show an estimation of the process of a mysqldump. It does so by calculating the size of all the tables in the given database and comparing this with the size of the resulting sql file.


if [ -z "$dbname" ]; then
echo "$0: Missing database operand."
echo "Usage: $0 database_name"
exit 1

MB=$(echo "1024*1024" | bc)
outfile="$(date +%Y%m%d)".$dbname.sql

size=$(mysql --defaults-file=/etc/mysql/debian.cnf --silent --skip-column-names \
-e "SELECT CEIL(SUM(data_length) / $MB) \
FROM information_schema.TABLES \
WHERE table_schema='$dbname';")

echo "Export will be around "$size"MB."

mysqldump --defaults-file=/etc/mysql/debian.cnf --single-transaction --compress \
$dbname | pv --progress --size "$size"m > $outfile

echo "File written to: $outfile"

realsize=$(ls -s --block-size=$MB $outfile | cut -d' ' -f1)
echo "Actual filesize is "$realsize"MB."

exit 0

Simply save the snippet above asmysqldump-progress.shor something similar. The usage is quite simple:

bash databasename

Allthough this method isn't precise at all, it gives a good indication of the progress. Handy dandy when exporting bigger databases.