Tips – Backup MySQL database and email the results using Cron Jobs

Cron jobs allow you to automate certain commands or scripts on your site. You can set a command or script to run at a specific time every day, week, etc. For example, you could set a cron job to backup your MySQL  database everyday so that you can recover your data if anything happen to your data like data missing and etc.

Here I want to share with you’ll on how to backup MySQL database and email the results automatically using Cron Jobs and cPanel (Shared Hosting). To doing this, follow the following step:


1. Copy the following codes into notepad and save it with some name with extension “.sh”. For example, I name it with “Mysqlbackup.sh”

2. Set the 4 variables, DBNAME, DBPASS, DBUSER, EMAIL using the information from your wp-config.php file. Others is optional.

3. Transfer the “Mysqlbackup.sh” using FTP into your shared hosting. Put it into /etc directory.

4. Login into your cpanel and directly go to Cron Jobs

5. Make sure that you have an appropriate permission on updating file. If you found an error about file permission, please contact your Web Hosting administrator for help

6. Let say everything is OK, you can view an options to choose your experience level. Select “Standard”

7. Enter an email address where the cron output will be sent.

8. Enter the column for command to run with following command. Replace “<username>” with you hosting username:

 

9. After that, set the schedule to the command need to run. You can select to run every 5 mintes first to check where the script and command working perfectly. If every thing fine, just re-schedule it, run every 12.00am would be good enough!

10. Save you Crontabs and you’re done!

Related Posts Plugin for WordPress, Blogger...

Leave a Reply

Your email address will not be published. Required fields are marked *