The “Cron Jobs” option in cPanel allows you to automate the execution of scripts or commands at regular intervals on shared hosting environments. This is particularly useful for automating file and database backups without manual intervention.
To perform a full backup of your files and MySQL database via a Cron job, you’ll need to use two separate commands (or a combined command within a script). Here are the main steps:
- Access the cPanel Management Interface :
- Go to the Advanced section > Cron Jobs :
- On the Cron Jobs interface, you can set up automated backups for your files or databases, depending on your requirements. Below is an example :
Each asterisk represents a unit of time or date:
- Minute (0-59): The minute of the hour when the task should be executed.
- Hour (0-23): The hour of the day when the task should be executed.
- Day of the month (1-31): The day of the month when the task should be executed.
- Month (1-12): The month during which the task should be executed.
- Day of the week (0-6): The day of the week when the task should be executed (Sunday = 0 or 7).
You can also configure your backup by selecting options from the dropdown lists according to your needs.
- Regarding the command lines for backing up website files and databases, please run the following queries :
- Website files backup :
cp -r /home/CPANEL_USERNAME/public_html /home/CPANEL_USERNAME/backup_files_YYYY-MM-DD
- Database backup :
/usr/bin/mysqldump DB_NAME > /home/CPANEL_USERNAME/backup_DB_NAME_YYYY-MM-DD.sql
*YYYY-MM-DD: Enter the date of the backup you want in this format.
*CPANEL_USERNAME: Enter the username of your cPanel account.
*DB_NAME: Enter the name of your database.
IMPORTANT: Automating backups will result in using the disk space included in your hosting account, since backups will be saved directly to this space.