Thursday 30 September 2010

A little bit more than MySQL dump

As MySQL is widely used, it is often database administrators have to backup database to save potential hazards. I believe "mysqldump" must be one of the most popular tool to backup MySQL database. Some other tech geeks may prefer GUI tool like phpMyAdmin. But whatever tool you use, you will realise that the output file is in plain text. In another word, it is wasting space, why can we not just do a bit more lazy click to make it compressed? Here is what I do under Linux.

#mysqldump -u dillon --password=xxxx database | gzip -c > /mnt/backup/db_`date +%Y%m%d%H%M`.sql.gz

It dumps database to a compressed file with date and time in the file name.

If you want to make it as a script or put it in corn job. Don't forget % need to be escaped.

#!/bin/bash
mysqldump -u dillon --password=xxxx database | gzip -c > /mnt/backup/db_`date +\%Y\%m\%d\%H\%M`.sql.gz

No comments:

Post a Comment