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 so fortunate that they never ever lost their database. Lucky for them.
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. firstname.lastname@example.org, 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
- PHP 4.1+
- SSH access to your web server,
or Cron Jobs interface (Unix/Linux),
or Scheduled Tasks interface (Win)
Install and setup (with SSH)
- Open “index.php” in you text-editor and change settings. If you’re not sure about something, leave the default values. Database settings, full path to script and your e-mail are required.
- 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.
- Open “.htaccess” file provided in the package and remove “#” from the first line to enable script protection. If you lost this file, simply create new .htaccess file, add “deny from all” (without quotes) and save it.
- Connect with SSH to your server, type
crontab -e(to edit Cron schedule table) and the text editor should show up.
- 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.phpmeans that PHP will execute the script, and
>/dev/null 2>&1tells 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 * * 0 every Sunday at midnight
(0 = Sunday, 1 = Monday, ...)
Control + Xto close the file, type Yto save changes, press Enterto confirm.
crontab -lto check if everything is set properly. If it is, exit command line.
- Wait for the first backup to arrive in your mailbox.
- If you received the backup file, you're done. Buy yourself something nice!