cPanel Automated Backup Script

Update: This script is now housed and maintained on my other website,


This is a simple script derived from the cPanel process that generates full account backups, only in PHP form. This makes the task of backing up your site easier and more reliable by allowing you to generate and maintain your own full site backups.


  • Automatic backup via Cron job
  • Generates an actual cPanel backup in tar.gz format
  • Very easy to set up, and executable with only one simple command
  • Email notification when the backup is complete
  • FTP option to transfer the backup file to a specified FTP server
  • Compatible with x3 themes


  • cPanel 10 or higher with Cron job and backup functionality enabled
  • PHP 4.1.x or higher
  • FTP access (optional)

How to Use:

  1. Download the script to your computer and extract the tarball
  2. Edit the cpanel_backup.php file with your cPanel settings:

$cpuser = Your cPanel username

$cppass = Your cPanel password

$domain = The domain name where cPanel is run, usually without the www’s

$skin = cPanel skin that you are currently running. This will usually be “x3” if you’re on cPanel 11 and “x” if you’re still on 10 (which I hope you’re not) but your webhost may have changed this. You can double-check by logging into cPanel and viewing your server settings:

cPanel Server Settings

The next section will set up the FTP options to upload the backup tarball to a server. If the FTP location is the same as the server you are doing the backup on, you should leave these fields blank.

$ftpuser = Username for your FTP site

$ftppass = Password for your FTP site

$ftphost = FTP hostname (usually

$ftpmode = The mode in which you would like to have the file transferred. I would recommend “passive” mode, especially for larger sites.

$ftpport = The port for FTP access on the server

$ftpdir = The remote directory, starting from the root of the FTP directory. If FTP server is the local server, this must NOT be the home folder of the user, as cPanel will automatically delete the backup after it is completed.  Example: /backups (/home/$user/backups).  Directory must exist.

$notifyemail = The email address that the backup confirmation should be send to once the backup is complete

$secure = Whether or not to allow the script to access your cPanel through its secure ports

$debug = Whether or not to show the detailed backup results in your confirmation email

4. Once the php file has been configured, upload it to your webserver. For security’s sake, it is very important that you make sure this file is located outside your document root (public_html) with permissions of 600

5. Now, all you need to do is set the crontab. Log into your cPanel and go to the “Cron Jobs” section and choose “Standard.” Here is where you will create the actual cron job to run the script whenever you want:


cPanel Cron Job

The command may vary depending on the setup of PHP on your server, but your Cron command will be as follows:

php -q /home/username/cpanel_backup.php

Known issues:

  • Users having the rvskin theme have indicated that using ‘x3’ at the theme may work, but others have said that the the script just doesn’t work at all.  I’d say just try running a backup manually and see what theme is in your URL when you do it, and use that.

Upcoming Features:

  • Support for SSH/scp
  • Option to just back up MySQL databases or home directory
Be Sociable, Share!

143 thoughts on “cPanel Automated Backup Script

  1. Thanks for the reply, I don’t think it’s working yet I’ve set it up word for word, I’ve set it to backup once a week. I’m not sure to set ftp to active or passive though, does this matter?

  2. My inmotion-hosted website has grown to the point where inmotion won’t back it up unless I pay for an expanded plan. I’d much rather just do the backups myself – but, every time I use the compress feature of the cpanel, it craps out somewhere between 2-3 GB compressed. (My site is now ~15GB.) So I can’t see how this script will work for me.

    It makes sense that I do a full backup, and then incrementals for files that change or get added (including a MySQL backup for my phpBB forum). That way, inmotion would suffer less load, and I wouldn’t have to suck off the entire website every night. But since inmotion won’t permit ssh or even rsh, I can’t rsync.

    It would be sweet if there were a program that looked at the directory and ftp’d only those files that changed (could that be yafc? I don’t know enough about it). Anyway, I’m still looking. It doesn’t benefit me that my inmotion plan provides unlimited storage if that plan makes no provision for me to easily make backups – without incurring additional cost.


  3. Me being an employee of IMH, if your site is on a server where the backup option is disabled, it means your site is probably over 10G. Trying to run a cPanel backup on a shared server when you have a 10G+ site is a problem – it taxes the CPU and we generally end up killing the backup because the servers go nuts when customers with large sites do them. Please keep in mind that as with ALL hosts that allow unlimited disk space, there is always the expectation of appropriate use. It’s not appropriate to tar up 10G+ worth of data on a shared server, so we don’t allow it.

  4. Is it possible to have the backups saved to a folder inside the root?

    That’s what I’m trying to do, I set up an FTP account at home/username/folder. I filled out the FTP fields as well as the cPanel.

    The reason for this is because my backups are magically disappearing occasionally.

    Thank you in advance.

  5. This is totally off the present subject, but I can’t seem to connect to anyone at IMH that will send a reply, so here it is: I have been trying to follow the IMH Community postings, for which you are listed as a moderator, however, I cannot see where any of the posts (including mine) have been looked at or answered in the last four months or so. I see where a number of people have joined but all of them also show zero posts, zero looks, and zero answers. It seems strange that someone would go to the rouble of joining a group and then not post anything. Has the IMH Community been replaced with some other form of communication, user group, blog, etc? Thanks.

  6. Hey V-nessa thanks for sharing this.

    Any updates on the home directory only backup and/ or the mysql database backup script updates?


    Bye !

  7. Yeah, so I can’t get this to work. I set everything up the way you describe. When the cron runs I get an email (in debug mode) that is a ton of html (maybe fullbackup.html?).

    I had to change some of the stuff in the ‘fputs($socket,”POST’ line because it was saying that file wasn’t found. I think it is probably looking for fullbackup.html and not dofullbackup.html, right?

    So I don’t think I am getting any errors or notifications but I am also not getting any full backups. Any ideas?

  8. Hi do you go out with older guys, I’m only 49. Haha just kidding my TechnoQueen. Seriously, will this script backup the MySql Databases and E-mail and filters – alias? As you know this works with the Cpanel Full backup when you do it manually. At least it does on my Hostgator account.

  9. There needs to be an update with the following modified

    After the $ftpmode line add

    $ftpport = “21”; // FTP Port number
    $ftpdir = “/backups”; // Your backup path

    And then modify the line that has

    $params = “dest=$ftpmode&email=$notifyemail&server=$ftphost&user=$ftpuser&pass=$ftppass&submit=Generate Backup”;


    $params = “dest=$ftpmode&email=$notifyemail&server=$ftphost&user=$ftpuser&pass=$ftppass&port=$ftpport&rdir=$ftpdir&submit=Generate Backup”;

    to add in the two new settings and then you are good to go.



  10. hmm my previous comment seems to have cut off text for the params, so here is what it should be, but you will need to remove the wrapping

    $params = “dest=$ftpmode&email=$notifyemail&server=$ftphost
    $ftpdir&submit=Generate Backup”;

    Hope that reads ok now.


  11. Hello, im using the script on cpanel

    The script run and do the backup, the problem is that the script seems to put another ftppass… this is my result:
    pkgacctfile is: /home/xxxxxxx/backup-8.6.2011_05-08-02_xxxxxx.tar.gz
    md5sum is: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    size is: 3059501

    homesize is: 36864
    Net::FTP>>> Net::FTP(2.77)
    Net::FTP>>> Exporter(5.58)
    Net::FTP>>> Net::Cmd(2.29)
    Net::FTP>>> IO::Socket::INET(1.29)
    Net::FTP>>> IO::Socket(1.29)
    Net::FTP>>> IO::Handle(1.25)
    Net::FTP=GLOB(0x90949f0)<<< 220———- Welcome to Pure-FTPd [privsep] [TLS]
    Net::FTP=GLOB(0x90949f0)<<< 220-You are user number 2 of 50 allowed.
    Net::FTP=GLOB(0x90949f0)<<< 220-Local time is now 05:08. Server port: 21.
    Net::FTP=GLOB(0x90949f0)<<< 220-IPv6 connections are also welcome on this server.
    Net::FTP=GLOB(0x90949f0)<<>> USER xxxxxxxx
    Net::FTP=GLOB(0x90949f0)<<>> PASS ….
    Net::FTP=GLOB(0x90949f0)<<>> TYPE I
    Net::FTP=GLOB(0x90949f0)<<>> CWD /
    Net::FTP=GLOB(0x90949f0)<<>> ALLO 3059501
    Net::FTP=GLOB(0x90949f0)<<>> PORT 127,0,0,1,140,241
    Net::FTP=GLOB(0x90949f0)<<>> QUIT
    Net::FTP=GLOB(0x90949f0)<<< 221-Goodbye. You uploaded 0 and downloaded 0 kbytes.
    Net::FTP=GLOB(0x90949f0)<<< 221 Logout.

    Can somebody help me?

  12. my previous comment seems to have cut off text:

    Net::FTP=GLOB(0x90949f0)>>> USER xxxxxx
    Net::FTP=GLOB(0x90949f0)<<>> PASS ….
    Net::FTP=GLOB(0x90949f0)<<< 530 Login authentication failed

  13. cut off text again

    Net::FTP=GLOB(0x90949f0)>>> USER xxxxxx

    <<>> PASS ….
    Net::FTP=GLOB(0x90949f0)<<< 530 Login authentication failed

  14. AFFFF ther are cut off text and i cant fix it:

    USER xxxxxx
    User xxxxxx OK. Password required
    PASS ….
    Login authentication failed

  15. Hello Nessa!
    Great Script!!
    Is it possible to backup to set it up only to backup a specific folder inside the home directory?

  16. Hey guys,

    I don’t know whether this script is actively being maintained, but I’ve seen problems with the latest version of cPanel/WHM… there are other options that are also free.

    We have a script for cPanel, and a script solely for MySQL Databases.

    Hope it helps.

    If you need Amazon S3, you can try as one option…


  17. All –

    Sorry for the delay on this. The script has been updated to work with cPanel 11.34 and 11.36, and requires a couple modifications to your FTP settings. Please see setup info in the post, specifically related to $ftpport and $ftpdir!

  18. Hi Vanessa,
    Thanks in advance. I want to migrate few websites to another WHM server, database server is already synced on secondary server. But now how can i migrate website with 30GB data with cpanel automated script. If i rsync directory to secondary server and create backup with skiphome, but still it gives errors at restoration.
    Also can you please help in create a replica of WHM server and keep both in sync.

    Lokesh Jangir
    Linux Engineer

Leave a Reply

Your email address will not be published. Required fields are marked *