How to take MySQL database backup using cPanel cron? Print

  • 0

Today, we will guide you on how to take MySQL database backup using cPanel cron. In order to secure MySQL database backup using cPanel cron, you need to perform the following steps.

Secure MySQL database backup using cPanel cron

  1. Login into your cPanel account.



  2. Go to the Advanced section and click on the Cron Jobs option.





  3. In the Email field, enter the email address on which you want to receive a notification of the result every time the cron job runs. Here, we have entered an email address [email protected] as an example.



  4. Click on the Update Email button to update the Email address entered in the Email field.





  5. Once you click on it, the email address will be updated and it will show under the Current Email section.



  6. In the Common Settings field, you will get a list of common settings such as Once Per Day or Once Per Week. You can select it as per your requirement.





  7. If you don't get a setting that fulfills your needs in the list of common settings, enter a time interval in the boxes on the left or use the menus on the right to select from typical entries for each period.



    Here, we have selected the backup frequency Once Per Day as an example. The cron job will do a backup of the database every day at midnight. It will save the backup with the current date appended to the file name.





  8. In the Command field, you need to enter the command or the path of your script. Since we want to secure a backup of MySQL database through a cron job, we will enter the following command to secure a backup of the MySQL database.

    date=`date -I`; /usr/bin/mysqldump -udbusername -ppassword dbname > /home/cPanel_username/Database_backup/Backup_name$date.sql


    Important Notes:

    • udbusername - There should be no space between -u and DBUSERNAME, DBUSERNAME is the username of the database you are trying to backup.

    • ppassword - There should be no space between -p and PASSWORD. PASSWORD is the password of the database user.

    • dbname- This is the name of your database.

    • /home/cPanel_username/Database_backup/Backup_name$date.sql -
    • cPanel_username - It is your username which you use to login into your cPanel account.

    • Database_backup - It is a directory name that we have created under the home directory (home/cPanel_username) to store the database backup into it. You can create a directory and name it as you wish.

    • Backup Name - It is the name of the backup which you want to set. But adding $date at the end will append the date to that backup.

  9. Click on the Add New Cron Job button to add the cron job in the cPanel.





  10. Once you click on it, it will be added and you will see it under Current Cron Jobs.



Verification of the database backup

In order to verify the database backup is generated or not through cPanel cron, you need to go to the path which you mentioned in the command. Below are the steps on how to verify the database backup generated by cPanel cron.

  1. Click on the Home icon located on the upper left side of the screen to go back to the cPanel home page.





  2. Go to the Files section and click on the File Manager option.



  3. Once you click on it, a new window will be opened with the name File Manager. You need to navigate the path which you have mentioned in the command to store the database backup. In this article, we have mentioned the database backup path is /home/demovpstest/database_backup/ so we will go on that path.

  4. Click on the home and double-click the database_backup directory to open it.



  5. You can see that the MySQL database backup is generated by the cron job. That’s all.







Was this answer helpful?

« Back
Sign up for a newsletter

chat