cPanel Automated Backup Script
Note: This is the same script originally housed on our author’s website, v-nessa.net.
cPanel Automated Backup Script (1.2 KiB, 19,324 hits)
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:
- Download the script to your computer and extract the tarball
- 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” or “paper_lantern”. You can easily verify this in the left-hand stats bar of cPanel or looking at the cPanel URL in your browser when you are logged in.
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 ftp.yourdomainname.com)
$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:
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