September 26, 2005
Database Backups
I just uploaded a little php script that will make a backup copy of your database if anyone needs one. A friend of a friend had a little issue the other day where a database managed to get messed up a bit, and the backups being made automatically by the server were corrupted.
That's not terribly unusual, since full site backups take a lot longer than just a database backup, and normally hosts will not stop a site during the backup procedure. So if the database gets hit during the full site backup it can corrupt the backup.
Breaking it out in a little script like this brings the possibility of it happening down considerably. Even with rather large databases the entire process will typically complete in just a few seconds, instead of many minutes.
It can be downloaded (as a zip file) at: Dababase Backup
There are just a few variables you'll need to configure, such as you database name, user and password, whether you want the backups to be compressed to save disk space, etc. I've included complete instructions via comments, commented the entire file, and of course it's released as GPL licensed.
If you want to automate it, simply set up a little cron job to run it daily or whenever you need it to run. An example of this, to get you started would look something like the following if you wanted it to run at 3:15AM Server Time each night:
15 3 * * * wget -q http://user:password@www.yourdomain.com/sqldump/dbdumper.php -O /dev/null
With the "user:password" indicating whatever username and password you set up to restrict web-capable entrance to the directory where your MySQL dumps are going to be stored.
Enjoy!