Automatic cPanel Backup Using Cron Jobs

Mar 25, 2016
• Shah

Being a website owner, It is really important to have a recent backup of your website. cPanel, the most popular web hosting control panel, provides a powerful Full Backup feature. Generating a full website backup with cPanel’s Full Backup can be simple but not completely automated.

If you’re someone who adds new content to your website regularly, You probably don’t want to login into your cPanel each time just to take a backup. Instead you can set up Cron jobs on your cPanel account to take a backup of all your file and databases.

Cron jobs allow you to automate certain commands or scripts in your cPanel account. You can set a command or script to run at a specific time at a specified interval.

Sounds cool, right? Let me show you how to set up Cron jobs to automatically take backup of your data. Basically, We will set up two Cron jobs. One for archiving the files and the other one for generating a backup of the databases.

Setting Up Cron Job To Backup The Databases

Now, to backup all the databases in your cPanel account, mysqldump command can be used. Copy-Paste the following command in the Command field.mysqldump --opt -Q -u YOUR_CPANEL_USERNAME -p'YOUR_CPANEL_PASSWORD' --all-databases > /home/YOUR_CPANEL_USERNAME/backup/databases.sql
Make sure to replace YOUR_CPANEL_USERNAME and YOUR_CPANEL_PASSWORD with your actual cPanel credentials.

Click on Add New Cron Job button to create the Cron job.

Setting Up Cron Job To Backup The Files

The tar UNIX command can be used to archive all the files in your cPanel account. Copy-Paste the following command in the Command field.tar -cvpzf /home/YOUR_CPANEL_USERNAME/backup/files.tar.gz /home/YOUR_CPANEL_USERNAME/public_html
Make sure to replace YOUR_CPANEL_USERNAME and YOUR_CPANEL_PASSWORD with your actual cPanel credentials.

Click on Add New Cron Job button to create the Cron job.

Once you have set up both the Cron jobs, A backup of your databases and files will be automatically generated every day. You can, of course, change the time interval for the Cron jobs. The backup files will be available for you to download from the “backup” directory in your cPanel account’s root directory.