Exporting Mysql database with progressbar
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.
Simply save the snippet above as dbexport.sh
or something similar. The usage is quite simple:
Although this method isn't precise at all, it gives a good indication of the progress. Handy dandy when exporting bigger databases.
Importing Mysql database with progressbar
Even though the script will output an example one-liner how to re-import the export, the file can easily be imported with the following command:
Don't forget to point to the proper filename and set the proper dbname.
Import / Export with MariaDB --defaults-file=/etc/mysql/debian.cnf obsolete
As you may know, some of the original creators of MySQL created MariaDB, since they didn't like the direction Oracle was bringing the project in. Personally I'm a huge fan of open sourced, community-driven and free projects like this. Now, this script will absolutely work with MariaDB — since they're mostly backwards compatible — but might throw you errors in some versions. If so, simply remove the --defaults-file=/etc/mysql/debian.cnf
from the mysql
and mysqldump
commands.
If you're interested, the mysql
and mysqldump
commands work without credentials, because of the unix socket authentication plugin, which simply checks if you're root.
Updates
- 2023-05-30
- Added
$CORRECTIONPERCENT
to calculate 10% more size to correct for SQL overhead. - 2022-08-17
- Changed filename to include time too.
- Simplified filename to
dbexport.sh
. - Used mysqldump options from The best rsync incremental backup script.
- Added
gzip
compression, we're assuming a 90% compression ratio here. - Added separate section for MariaDB.
- 2020-05-05
- Added
sudo
to ensure access to defaults file. - Changed options to mysqldump to ensure large databases can be properly exported, also include events and routines.
- Remove the need for
bc
, makepv
show more details.