The Blog

Backup and Restore compressed MySQL databases using gz or bz2 Posted on

Backup

mysqldump --routines -u root -p --databases db1 db2 db3 | gzip > /var/www/backups/mysql/databases.sql.gz # multiple db using gzip
mysqldump --routines -u root -p --databases db1 db2 db3 | bzip2 > /var/www/backups/mysql/databases.sql.bz2 # multiple db using bz2

mysqldump --routines -u root -p db1 | gzip > /var/www/backups/mysql/db1.sql.bz2 # single db using gzip
mysqldump --routines -u root -p db1 | bzip2 > /var/www/backups/mysql/db1.sql.bz2 # single db using bz2

Restore

bunzip2 < db1.sql.bz2 | mysql -u root -p db1
zcat db1.sql.gz | mysql -u root -p db1

Same goes for multiple DBs just add one or more DB to restore at the end of the command, or leave blank to restore all.

This entry was posted in Uncategorized. Bookmark the permalink.

Please Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *



CAPTCHA
Change the CAPTCHA codeSpeak the CAPTCHA code