Backup2Mail — Automated database backups sent to your e-mail

Backup2Mail automagically creates regular backups of your database and sends them to your mailbox on a given schedule.

Download Backup2Mail (4KB .zip)

Why Backup?

Backing-up a web site’s database is considered a common sense. We all know that, yet we often forget about it.

Some people are fortunate 100 who never ever lost their database. Lucky for them.
The rest of us are not, and we need an automated process.

What is Backup2Mail?

Backup2Mail is mini PHP application that creates regular backups of your MySQL database and sends it to configurable e-mail address. The whole process is scheduled with a help of Cron, a Unix program that runs programs at scheduled times.

Where to send your backups?

It is suggested to create a separate e-mail account, i.e. backup@yourdomain.com, which will be accessed via web mail if needed.

Gmail is great option due to its storage capacities, but in case you have overly sensitive data, you'd probably want to store backups on a server under your control.

Note: If you have really big database and you download it every day (or few times a day), your mailbox could quickly exceed the quota limit!

Web server requirements

Install and setup

  1. Open 'index.php' in you text-editor and change settings. If you're not sure about something, leave the default values. Database settings and your e-mail are required.
  2. Upload folder in your public web folder to test it. Open the file in your browser. If you see the black page with green letters and there's no errors, you can proceed.
  3. Create new folder 'backup2mail' in your web root, above the public web folder — you don't want someone to run the script from the browser, right?
  4. Move all files from your temporary folder to 'backup2mail'
  5. Connect with SSH to your server, type crontab -e (to edit Cron schedule table) and the text editor should show up.
  6. Add the following line:
    0 0 * * * php /home/your_account/backup2mail/index.php >/dev/null 2>&1

    Numbers and asterisks are the interval part, see the cheat sheet below.
    php /home/your_account/backup2mail/index.php means that PHP will execute the script, and >/dev/null 2>&1 tells Cron not to send output to e-mail specified in the first line of Cron configuration file.

    Replace 'your_account' with your account username, and adjust the interval (the above is everyday at midnight).

    Interval cheat sheet

    * * * * *every minute
    0 0 * * *every day at midnight
    0 5 * * *every day at five o'clock in the morning
    (11 = 11AM, 23 = 11PM)
    0 0 * * 0every Sunday at midnight
    (0 = Sunday, 1 = Monday, ...)
  7. Hit Control + X to close the file, type Y to save changes, press Enter to confirm.
  8. Type crontab -l to check if everything is set properly. If it is, exit command line.
  9. Wait for the first backup to arrive in your mailbox.
  10. If you received the backup file, you're done. Buy yourself something nice!