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
7 years ago

Hi Eric,

Thank you for your script.

However, I receive an email from Cron Daemon saying “Error backing up server”.

I am using Hostgator. How can I check what went wrong please?


7 years ago

One thing I’ve noticed is that the FTP session will not create the ftp directory if it isn’t found.

So if $ftp_directory = “/folder/”; there already has to be a directory called “folder” on the recipient’s root.

I would like to auto-create folder names based upon the date, with directory names such as “09-17-2016”, so that I can automatically organize multiple backups from multiple cpanel accounts on the same recipient server. This way, I could assign a value such as $ftp_directory = “/”.date(‘m-d-Y’, time()).”/”; for each day’s backup.

Is there a way to accomplish this?

7 years ago


7 years ago

All this needs is another cron job or something to delete backups older than X or after X newer backups; I keep hitting my storage limits and having to manually delete stuff.

7 years ago

Thank you very much. Did everything as stated. Your blog is worth a bookmark

8 years ago

Where exactly does it save the back up to? I can’t seem to find it

Cpanel Automatic Login | Cloud Email Services
8 years ago

[…] Howto: Automatic cPanel Backups / Eric … – July 21, 2013 Howto: Automatic cPanel Backups. Intro: As many web devs know, the web hosting panel, cPanel, has quite a powerful “full backup” feature. […]

8 years ago

Ok… well… I tried but it just didnt work out which is very very sad.
The backup ZIP has been created but the backup hasn’t been uploaded to my NAS.
Yes… my remote FTP config is 100% ok.
This is the message I received from the server:

HTTP/1.1 303 Moved
Server: cpsrvd/
Connection: close
Content-length: 254
Location: /frontend/x3/h/backup/dofullbackup.html?dest=ftp&
Content-type: text/html; charset=”utf-8″
Cache-Control: no-cache, must-revalidate
Pragma: no-cache

PS. The login details are not real. I just changed it for this comment.