How to take MySQL database backup using cPanel cron? Print

  • 2

cPanel offers a cron that allows you to run your commands or scripts automatically at certain times. You can choose the time as per your requirement that could be every month, every week or every day. A database stores the critical information of your website. Therefore, you should take the backup of your database at regular intervals. Please refer to the following steps on how to set up MySQL database backup daily.

  1. Login to your cPanel.

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

  3. In the Cron Jobs section, you will see the Cron Email option. It can send an email every time cron runs a command which produces output. If you do not want an email to be sent for an individual cron job, you can redirect the command’s output to /dev/null. For example yourcommand >/dev/null 2>&1. You can enter your email account for this.

  4. At the add new corn job and common settings, select once per day.

  5. Now at the command box, enter the below command. 

    mysqldump -uroot -ppassword --opt accu_4 > /home/mysql_backup/accu_4-$( date +"\%Y_\%m_\%d" ).sql

    You will need to make the following changes in your command. 

    root: Change it to your database user. 
    password: Change it to your database user password
    accu_4: Change it with your actual database name.
    /home/mysql_backup/ : Path where backup file will be added. You can change the path as per your requirement.

  6. Click on Add New Cron Job button.  cPanel cron will take the backup of your database daily 00:00.

    You are done with MySQL database backup using cPanel cron. 

Was this answer helpful?

« Back