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
- PHP 4.1+
- Either Command line access to your web server,
or Cron Jobs interface (Unix, LInux),
or Scheduled Tasks interface (Windows)
Install and setup
- 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.
- 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.
- 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?
- Move all files from your temporary folder to 'backup2mail'
- 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, ...) - Hit
Control + X to close the file, typeY to save changes, pressEnter to confirm. - Type
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!