Howto: Automatic cPanel Backups

Intro: As many web devs know, the web hosting panel, cPanel, has quite a powerful “full backup” feature. The only problem is that if you want a full backup, you have to log into cPanel, navigate to the backup page, click the backup button, wait for the backup to finish, and then download it. If you’re like me, and would like to make sure I have frequent backups of everything, making backups can get annoying.

The following is a short 5 minute tutorial to set up your cPanel to automatically create backups and store them (for free) in another remote location via FTP using a PHP script and cPanel’s cron jobs.

Requirements:
1. Your cPanel login information
2. (Optional) A remote FTP location to store backups

Step 0 (Optional) – Get a FTP server to store backups:
Getting a remote place to store your backups is important. I highly recommend you check out Box (similar to Dropbox), which has a FTP uploading feature. For a list of free web hosts, click here (Make sure you read their AUP). Any server/web host will do, as long as you can FTP into them.

Step 1 – Get the backup script:
Visit this page to generate the PHP script that will run the backups. Fill out your cPanel information as well as your FTP server info, if you are using one. After you hit the submit button, copy the generated PHP code and save it as backup.php. Put the backup.php file into your cPanel Home directory (Go into your file manager and click “Home”)

Step 2 – Set up cron:
Go to your cPanel homepage and press the “Cron jobs” link. In the “Add New Cron Job” section, select from “Common Options” how often you want to create a backup (or customize your own interval). I suggest once a day. You can choose once a week if your website is static or doesn’t change much. In the “Command” field, type php -f ~/backup.php. Press the add button and you’re done!

That’s it! Pretty simple and effective way to make sure you always have backups. It’s even possible to upload to two different FTP servers, just create two backup scripts and cron jobs. Make sure you log into your remote backup FTP server to download and remove old backups.

Bonus: Here’s a script you can put onto your remote server (in the same directory as your backups) that will automatically delete backups older than 7 days to save storage space. Add it as a cron job and you’ll be set for worry-free backups!

Leave a Reply

35 Comments on "Howto: Automatic cPanel Backups"

hi,
Thanks for this script. However I have a problem,
“No input file specified.”

Does this script need to store the backup archive on the website server before sending it out by ftp? An important consideration when disk space is tight.

Hi Erin,
Great script.
Curious if you’ve developed a script to only backup MySQL databases and FTP/SFTP them/Email?

Joel

Hi eric,

i want to backup my cpanel account and transfer this backup directly to dropox,
How can i do this ?
PLease give me reply, it’s very important for me.

Thank you

It works! Thank you!

Hi Eric, Thanks for this amazing script. However I get the following errors when the cron is executed: Cannot load the ionCube PHP Loader – it was built with configuration 2.2.0, whereas running engine is API220090626,NTS Failed loading /usr/local/lib/php/extensions/no-debug-non-zts-20020429/xcache.so: /usr/local/lib/php/extensions/no-debug-non-zts-20020429/xcache.so: cannot open shared object file: No such file or directory Failed loading /usr/local/Zend/lib/ZendExtensionManager.so: /usr/local/Zend/lib/ZendExtensionManager.so: cannot open shared object file: No such file or directory Warning: PHP Startup: It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you… Read more »

Hi, thank you.
Have problem, get
“Failed to open socket connection.” can figured what I make wrong?

Is it possible to make that backup is compressed with .zip, .rar, .tar or something?

Best regards

I get the same.

Thank you, this has been very helpful.

Hi there, anyway to exclude certain folder from the backup? I’m currently storing the backup in root but the backup picks that up for backup again and the file size just keep on piling.

1 2 3 4
wpDiscuz