Many Web Applications are changing daily. In case your site is hacked or its data becomes corrupted, it is beneficial to have regularly stored backups of your databases so you can restore your account quickly. Luckily, there is a quick and reliable way to do this through the use of Cron Jobs. Below is a step by step process on how to set up Cron Jobs to take backups of your Databases, and then have them emailed to you.
1) Download the following zip file.
email-db-backup
2) Extract the zip file and open the “backup.php” file in the “mtebackup” subdirectory with a text editor such as notepad or TextEdit.
Windows User help for extracting .zip files.
3) Change the following details to your database information and email information:
$dbhost = “localhost“; // leave this as localhost for most sites $dbuser = “dbuser“; // enter your database username here $dbpass = “dbpass“; // enter your database password here $dbname = “dbname“; // enter the name of your database here $sendto = “Send To <sendto @email.com>“; // the email address you are sending to $sendfrom = “Send From <sendfrom @email.com>“; // This will be the reply to email address $sendsubject = “Daily Database Backup“; // the subject of the email $bodyofemail = “Here is the daily backup of my database.“; // The message included within the email |
Note: The items in red are to be changed and configured to match your settings. The items in green are comments on what these changes will do.
4) Save the file and upload the entire “mtebackup” directory to your cPanel account. For this guide, please upload the mtebackup folder to your public_html directory.
If you do not already have an FTP client set up for accessing your web hosting account, you can download and install Filezilla, a free open-source FTP program. To connect to your site, please follow Filezilla’s instructions on FileZilla’s Client Tutorial page.
5) Log into your cPanel. Locate and click on “Cron Jobs”
6) Set the Cron Job to run at the desired time, (it is usually best to run this through the middle of the night,) then put the following command in the “Command:” box with your username in place of “cPanelusername”
php -q ~cPanelusername/public_html/mtebackup/backup.php
Note: Please change the cPanelusername to match your cPanel/FTP username. This assumes that you uploaded the file to your “public_html” directory. If you uploaded the folder to a different location you will need to update the command to reflect that path.
7) Your backup Cron Job will now be listed in the “Current Cron Jobs” section.
8) Sit back and enjoy receiving emails with daily backups of your database.