MySQL Automated Backup Tool

TOP del.icio.us

So I was sitting at work either writing a complex database driven program or watching Stargate SG1, I´m not sure. My boss came in and asked me if the database got backed up anywhere. I said "Yup, it´s backed up onto the development server every day".
 
"Where is the development server?"
 
"It´s that one there",  I said, pointing at the Linux box balanced on the top of an old monitor on the edge of my desk.

 
"Ha huh. Can we do an off-site backup somewhere?"
 
So I did.  Since our databases are stored on several different servers I wrote a program to export each of the databases as a text file of SQL commands.  These files are then compressed into a gzip file and downloaded to the local server.  It also archives these by date so that I can keep an archive of our databases, gradually reducing the number of old files it keeps.
 
The next stage is to gzip all the files in the document root of our development web server, which also includes the gzipped sql files.  Since this is our development server it also contains copies of all the files for all the various the websites.  This final gzipped file now contains everything I need to restore any of our servers from catastrophe.

 
The final part then FTPs to my remote home server and uploads the gzip file to a protected directory. Bingo bango, job done!
 
Its all done in PHP using commands to standard Linux tools like wget, ftp, gzip and the mysql command line utility. With a little tinkering it should work on most linux setups.  If anyone thinks that this might be useful to you then drop a comment below and I might stick it up here for download.

One comment to “MySQL Automated Backup Tool”

  1. Comment by Andy:

    Oh yeah, forgot to mention that it can all be set to run by cron job so you can leave it alone and know that the backups are being run every day, night, week or whatever!

Leave a Reply