Mac/Linux – Backing up MySQL Databases

For similar reasons as to why I created drupal_db_dump for dumping Drupal databases; I wrote a wrapper script for the mysqldump command. One difference however, is that you can pass in options to the mysqldump command, which allows for greater utility. You do this by appending — to the end of the script and then specifying any valid mysqldump flags.

Example:

./msdw -d database1,database2,database3 -p /path/to/store/dumps -a — -u mysql_user –password=itsasecret –single-transaction

The only mysqldump flags you shouldn’t specify are ones relating to which databases to dump (ex: –all-databases). The database(s) you wish to dump must be the argument to -d flag and if you specify multiple databases, they must be separated by commas with no spaces in between. As with drupal_db_dump, specifying -a will auto-purge all but the last dump for the previous month when a new month begins. But again, by design, it will do this only if the backups span a maximum of 2 months.

For anyone wondering, msdw is an abbreviation for mysqldump wrapper. The guy that usually names my scripts got fired for being too verbose. drupab_db_dump, really? Terrible.