Take cPanel full backup-PHP

Hello Friends !!

I found some new thing to take backup your site/blog from server.

I give you script to take backup.

This will take full backup from cPanel to FTP.

The first, cpbackup_cfg.php, shown below, must be edited to insert your site and FTP server login credentials.

<?php
$cpuser = “xxxxxxxxxx”;
$cppass = “xxxxxxxxxx”;
$domain = “yourdomain.com”;
$skin = “x2″;

$ftpuser = “xxxxxxxx”;
$ftppass = “xxxxxxxx”;
$ftphost = “ftp.backupsite.com”;
$ftpmode = “passiveftp”;
$ftpdir = “/subdir”;

$notifyemail = “webmaster@mydomain.com”;

$delbackup = 1;

$secure = 0;

$debug = 0;
?>

The second file, cp_backup.php, shown below, is the backup script itself.

<?php
include(‘cpbackup_cfg.php’);
if ($secure) {
$url = “ssl://”.$domain;
$port = 2083;
} else {
$url = $domain;
$port = 2082;
}

if ($delbackup) {
$conn_id = ftp_connect($ftphost);
if ($conn_id) {
$ok = ftp_login($conn_id, $ftpuser, $ftppass);
if ($ok) {
if (!empty($ftpdir)) {
$ok = ftp_chdir($conn_id,$ftpdir);
}
if ($ok) {
$dirlist = ftp_nlist($conn_id, “backup*”);
if (!empty($dirlist[0])) @ftp_delete($conn_id,$dirlist[0]);
}
}
ftp_close($conn_id);
}
}

$socket = fsockopen($url,$port);
if (!$socket) { echo “Cannot connect to $url\n”; exit; }
$authstr = $cpuser.”:”.$cppass;
$pass = base64_encode($authstr);
$request_data = “dest=”.urlencode($ftpmode).”&email=”.urlencode($notifyemail);
$request_data .= “&server=”.urlencode($ftphost).”&user=”.urlencode($ftpuser);
$request_data .= “&pass=”.urlencode($ftppass);
if (!empty($ftpdir)) $request_data .= “&rdir=”.urlencode($ftpdir);
$request_data .= “&submit=”.urlencode(‘Generate Backup’);

fputs($socket,”POST /frontend/”.$skin.”/backup/dofullbackup.html HTTP/1.1\r\n”);
fputs($socket,”Host: $domain\r\n”);
fputs($socket,”Authorization: Basic $pass\r\n”);
fputs($socket,”Content-type: application/x-www-form-urlencoded\r\n”);
fputs($socket,”Content-length: “.strlen($request_data).”\r\n\r\n”.$request_data);

while (!feof($socket)) {
$response = fgets($socket,4096);
if ($debug) echo $response;
}
fclose($socket);
?>

After this run cp_backup.php file. It will create zip file in root folder.

If you have any query then post comment.

THanks…

You can leave a response, or trackback from your own site.

View Comments to “Take cPanel full backup-PHP”

  1. David Grega says:

    You may wish to consider refactoring your script to use our APIs, which can be accessed using just the cPanel user credentials. Our XML API can call the API1 function that triggers a remote backup. Feel welcome to contact me directly for assistance with doing this.

    Using our APIs will make your script work regardless of which cPanel theme the user is utilizing and will make your script more future-proof.

  2. admin says:

    Thanks to you David Grega.
    And I will contact you for this topic.
    Thanks again for your time.

Leave a Reply

blog comments powered by Disqus
Subscribe to RSS Feed Follow me on Twitter!
Get Adobe Flash playerPlugin by wpburn.com wordpress themes
Thank you for using IGIT Tweet Share Button, a plugin by HackingEthics