Mar 21, 2009
admin

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…

  • http://www.cPanel.net/ David Grega

    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.

  • http://www.cPanel.net David Grega

    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.

  • admin

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

  • admin

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

  • http://www.dailytuts.net/4579-take-cpanel-full-backup-php/ Take cPanel full backup-PHP | Dailytuts.net – Daily tutorial for peoples

    [...] Original post: Take cPanel full backup-PHP [...]

  • http://www.linkwayhosting.com linkway hosting

    Hi,
    Can you tell me exact code which create backup file ? (that.zip file)
    I want that backup.zip file to be uploaded on remote ftp server

  • http://www.linkwayhosting.com linkway hosting

    Hi,
    Can you tell me exact code which create backup file ? (that.zip file)
    I want that backup.zip file to be uploaded on remote ftp server

  • http://www.linkwayhosting.com linkway hosting

    How to show or store the name of backed up file in php variable ?

PHP Genious Services

I am a PHP freelancer india, PHP Developer india, PHP programmer india, Wordpress Freelancer india, Wordpress customization services, Wordpress Plugin Developer, Wordpress theme customization, Wordpress plugin customization, Magento Freelancer, Magento Developer india, Magento customization services, Magento theme integration, Opencart Developer india, Zencart Freelancer, Opencart customization, Opencart plugin development, HTML and CSS customization, cakePHP Developer, cakePHP Freelancer india, Ecommerce Developer india

Click Here for

Follow me on Facebook

Categories

Get Adobe Flash playerPlugin by wpburn.com wordpress themes