Tutorial : How to Shedule or make a backup for your database's using Cron Jobs in cPanel.
Well hello there, Say you want to backup your website database or maybe the latest backing up of your WordPress database in this matter. Lets work with a basic tutorial with backing up your WordPress database in this tutorial. We are aware that there are plenty of plugins around that can get the job done. Some of them backup only your database while others backup the whole WP directory. If you have used WordPress long enough, you will realize that these plugins are not reliable. They will work one day and fail another day, for thousand and one reasons. It could be that they are not compatible with the new WordPress version that you have upgraded to, or that they are conflicting with a newly activated plugin. As in my case, it could also because your database is getting too big for them to handle.Whatever the reasons, rather than relying on plugins, a better alternative is to use a cron job in your server and schedule it to backup your database everyday. This can even work in with any website or script. Just make sure you read in everything carefully. Keep it in mind : The only requirement is that you are using a Linux server to host your files and a control panel like cPanel which SixServe provides you with . Lets Begin Shall we ? Okay, 1. Login to your web host control panel (cPanel @ yourdomain.com/cpanel). If you are using cPanel, look for a Cron Job icon.
2. You can set the time and frequency to backup the database. Under the command field, copy and paste the following command:
mysqldump --opt -Q -u dbusername --password=dbpassword dbname | gzip > /path-to-store-the-backup-file/db_backup.sql.gz[/size][size=2]
- Replace dbusername with the database user.
- Replace dbpassword with the database user password.
- Replace dbname with the database that you are backing up.
- Replace the path-to-store-the-backup-file to the file path in your server where you want to save the backup.
Note: In some server's, you might need to put a pair of single quote around the dbpassword for it to work. For example:
mysqldump --opt -Q -u dbusername --password='dbpassword' dbname | gzip > /path-to-store-the-backup-file/db_backup.sql.gz[/size][size=2]
Now, E-mail yourself the Database -Storing the database on your server could take up plenty of storage space. One way you can do is to email the backup file to yourself.
- Download this php script.
- Extract the zip file and open the backup.php with a text editor.
- Change the database detail:
$dbhost = "localhost"; // usually localhost $dbuser = "dbuser"; //enter your database username here $dbpass = "dbpass"; //enter your database password here $dbname = "dbname"; // enter your database name here $sendto = "Send To <email@example.com>"; //the email address to send the database to $sendfrom = "Send From <firstname.lastname@example.org>"; $sendsubject = "Daily Database Backup"; //the subject of the email$bodyofemail = "Here is the daily backup of my database.";
- Save the file. Upload the whole folder to your server. Note: The folder includes a .htaccess file to prevent any access from the browser. If you want to access from the browser, remove the .htaccess file.
- In the cron job section of the cPanel, enter the following command:
php -q /path-to-the-php-script-folder/backup.php
Thats it , now you'r done. Enjoy your day and hosting with SixServe/Squidix Hosting.
Copyright SixServe Tutorials.