Electronic Engineering Blog

Backing up my BugZilla database

Now that I have bugzilla set up, my clients are starting to use it. It’s a very useful tool for logging bugs, feature requests and test results. The clients get kept up to date on what I’m doing, and I don’t have to remember every thing as it is all kept in the database.

That means that the database has to be protected from loss or damage by taking regular backups.

The bugzilla installation on my system uses MySql as the database engine, so I can take a backup of the entire bugzilla database by using the mysqldump command like this:

/usr/local/mysql/bin/mysqldump --user=bugzilla --password=******* bugzilla >backup.sql

That will create a human readable backup of the entire bugzilla database in the current directory.
To save space I can pipe the output through gzip to create a compressed output, like this:

/usr/local/mysql/bin/mysqldump --user=bugzilla --password=******* bugzilla | gzip >backup.sql

I can give the file a more useful location,  by specifying an explicit path for the output file, and while I’m at it I can format the file name to include the date on which it was created like this:

/usr/local/mysql/bin/mysqldump --user=bugzilla --password=****** bugzilla | gzip >/Users/bz/backups/bugs_backup_`date +\%Y-\%m-\%d`.sql.gz

So now I have a useful command that backs up the entire bugzilla database to a compressed file in a specific location, with a filename that includes the date of the backup. The output filename looks like this:


So, now to get the command to run automatically at midnight every night, I edit the root user’s cron tab file by using: (* See note below about ‘su’)

crontab -e

and append this (all on one line) to the file:

0 0 * * * /usr/local/mysql/bin/mysqldump --user=bugzilla --password=****** bugzilla | gzip >/Users/bz/backups/bugs_backup_`date +\%Y-\%m-\%d`.sql.gz

Now my bugzilla database gets backed up every day at midnight.


*NOTE. You must use ‘su’ instead of ‘sudo’ to edit the crontab, as you need to be editing the root user’s crontab file, not your normal user’s file. On most Mac machines the root user is not enabled by default, so see my other post ‘Setting the root user password on Mac OS X‘.

, , , , ,

Leave a Reply

%d bloggers like this: