Skip to content Skip to footer

Having Trouble Finding A Reliable Backup Solution For Cpanel?

Look no further, just by editing and uploading this php script to the home directing of your web server, you can have a automated backup solution for your cpanel.

Requirements

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

1. Create a file called cpanel_backup.php and copy the below script in to the file


<?php

// Permissions on this file should be 600

// Place outside your public_html

// ********* Configuration *********

// Info required for cPanel access

$cpuser = “cpanelusername”; // Username used to login to CPanel

$cppass = “cpanelpassword”; // Password used to login to CPanel

$domain = “domain.com”; // Domain name where CPanel is run

$skin = “x3”; // Set to cPanel skin you use (script won’t work if it doesn’t match). Most people run the default x theme

// Info required for FTP host

$ftpuser = “yourusername”; // Username for FTP account

$ftppass = “yourpassword”; // Password for FTP account

$ftphost = “ftpipaddress”; // Full hostname or IP address for FTP host

$ftpmode = “ftp”; // FTP mode (“ftp” for active, “passiveftp” for passive)

$ftpdir = “/”; //Ftp directory sent to

// Notification information

$notifyemail = “user@domain.com”; // Email address to send results

// Secure or non-secure mode

$secure = 0; // Set to 1 for SSL (requires SSL support), otherwise will use standard HTTP

// Set to 1 to have web page result appear in your cron log

$debug = 1;

// *********** Don’t Touch!! *********

if ($secure) {

$url = “ssl://”.$domain;

$port = 2083;

} else {

$url = $domain;

$port = 2082;

}

$socket = fsockopen($url,$port);

if (!$socket) { echo “Failed to open socket connection… Bailing out!n”; exit; }

// Encode authentication string

$authstr = $cpuser.”:”.$cppass;

$pass = base64_encode($authstr);

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

// Make POST to cPanel

fputs($socket,”POST /frontend/”.$skin.”/backup/dofullbackup.html?”.$params.” HTTP/1.0rn”);

fputs($socket,”Host: $domainrn”);

fputs($socket,”Authorization: Basic $passrn”);

fputs($socket,”Connection: Closern”);

fputs($socket,”rn”);

// Grab response even if we don’t do anything with it.

while (!feof($socket)) {

$response = fgets($socket,4096);

if ($debug) echo $response;

}

fclose($socket);

?>


2. After coping that make sure you edit only the variables that need to be changed

3. create a cron job on the cpanel using the following

php -q /home/username/cpanel_backup.php

4. Make sure the file is not in the home directory and also the file is chmod to 600

There you go, you now have a free and very reliable backup solution for your cpanel.