Backup MySQL to Gmail using PHP

Yesterday I rewrote a cool script to backup a MySQL database to a Gmail account using PHP.

The original source came from here, but I ended up rewriting over half of it because it did not work on our servers, and there was some other stuff that I did not like.

The script uses mysqldump to get a dump of your db, archives it, and emails it as an attachment to your gmail account. Remember, gmail has a 20mb limit on attachments.. but for most small sites that is more than you’ll ever need.

Here’s the rundown on how to use it:

1) Register a Gmail account to backup your db to.
2) Get these three files: mysql2gmail.php, class.phpmailer.php, class.smtp.php

wget http://dl.getdropbox.com/u/113063/mysql2gmail.php http://dl.getdropbox.com/u/113063/class.phpmailer.php http://dl.getdropbox.com/u/113063/class.smtp.php

3) Change the stuff on the top of mysql2gmail.php until it works.

Leave a Reply