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.

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!

Inline Feedbacks
View all comments
5 years ago

When I click Here it does not go to a backup PHP file.

5 years ago

The backed up file (winzip) is extremely huge. When I use this code of yours, the file size is 1.2 gb. If I go directly to CPanel & do the backup manually, the file size is 800+ mb. If I use WP Clone (wordpress plugin) & do the backup manually, the file size is 200+ mb. All backups are full backups.

Therefore, is there a way to drastically reduce the file size?

5 years ago

Hey~ I wanna backup cpanel emails only. How should i do?

6 years ago

In my case, I was able to get the script working again by using “passiveftp” instead of “ftp” for the “dest” parameter in case that helps anyone else. Thanks again Eric for a great script!

6 years ago

Awesome script and great write-up, thanks so much! However, a few weeks ago it stopped working for me and I’m wondering if you or anyone else reading this blog post has had a similar experience. I tried running the script manually and received this error: HTTP/1.1 500 Internal Error Connection: close Content-type: text/html; charset=”utf-8″ X-Error-Message: No response from subprocess ( (cpanel)): The subprocess ended prematurely because it received the ALRM (14) signal I can run the cPanel Backup Wizard via their web UI and it saves the file to the same FTP and I have otherwise assured the FTP server… Read more »

6 years ago

Hi There,
I am having issues getting this to work…. Is there any advise please?

kaari l
6 years ago

This is fantastic, exactly what I needed! Thanks for sharing. My cron daemon has the following problem “file_get_contents(http/frontend/paper_lantern/backup/dofullbackup.html): failed to open stream: No such file or directory in /home/pdialy/backup.php on line 43
Error backing up server.”
I don’t remember mention of “dofullbackup.html” in this article, but in the script, it states not to change that section. Any insight would be very appreciated 🙂

7 years ago

Need a bit of help here… I can get the script to run locally and create backup if I change $ftp = true to false. Backup size is about 2 gb. When I input the ftp information using port 21 (and change back to $ftp = true), I can see it logging into my Synology NAS but it logs out 1 minute later without uploading any data. The ftp account has a shared folder called allergynorthshore I’ve tried $ftp_directory = “/allergynorthshore” as well as “/allergynorthshore/” and “allergynorthshore/” and “/” but none change it so that the script actually writes data… Read more »