Compressing/Decompressing mysql dumps on the fly
Using pipes and redirection in the shell we can do backups or restore them, performing compression or decompression on the fly, this are the commands I frequently use:
Create a backup
ivan@mini:~$ mysqldump –h dbHost –u dbUser –pdbPass –add-drop-database –databases <dbname> | bzip2 > dbName-02-17-2010.sql.bz2</dbname>
If I want to restore the backup I use:
ivan@mini:~$ bunzip2 < dbName-02-17-2010.sql.bz2 | mysql –h dbHost –u dbUser –pdbPass
I can switch bzip2 compression by changing only the program name for example gzip/gunzip lzma/unlzma