How to take mysql database backup using cron job in cpanel

How to take mysql database backup using cron job in cpanel

  • 31 Jul, 2018
  • Technology


1. Login into cpanel

2. In "DATABASES" section click on "MYSQL Databases"

3. Select database name under "Current Databases" section, replace database name in cron command

/usr/bin/mysqldump -u Current User -p'Password' eduhubin_web_db > /home/cpanel-username/db_`date +\%Y\%m\%d\%H\%M`.sql



4. Select user under "Current Users" section

/usr/bin/mysqldump -u Current User -p'Password' eduhubin_web_db > /home/cpanel-username/db_`date +\%Y\%m\%d\%H\%M`.sql


5. Click on "Change Password" under "Current Users" section. Enter New Password and click on "Change Password" button


/usr/bin/mysqldump -u Current User -p'Password' eduhubin_web_db > /home/cpanel-username/db_`date +\%Y\%m\%d\%H\%M`.sql


Put password in cron job command

Note: There is no space between p and password command

6. Go to Cpanel home page/dashboard


7. In "ADVANCED" section click on "Cron Jobs"


8. Go to "Add New Cron Job" section

9. In "Comman Setting" select Cron Job occurrence nature

i.e. If you want to execute cron job for database backup every minute then select "Once Per Minute" option



10. /home/eduhubindia/db_`date +\%Y\%m\%d\%H\%M`.sql

a. Above is the path of output file,2nd parameter is username of cpanel, which you can find at top right of cpanel

b. Name of DB backup file is db_`date +\%Y\%m\%d\%H\%M`.sql

above code is added in file name so that timestamp can be added in dbbackup file name


10.  /usr/bin/mysqldump -u Current User -p'Password' eduhubin_web_db > /home/cpanel-username/db_`date +\%Y\%m\%d\%H\%M`.sql

Add above command In command line


11. Click on "Add New Cron Job" button

12. Go to Cpanel home page/dashboard

13. Click on File Manager

14. Check databack file is created