<?php
$cpuser = “cpanel username”; //cPanel Username
$cppass = “cpanel Password”; //cPanel Username
$domain = “yourdomain.com”; // Domain name you want to take backup
$skin = “x2″; // no need to change$ftpuser = “FTP username”; // FTP username
$ftppass = “FTP password”; // FTP username
$ftphost = “FTP host”; // FTP Host
$ftpmode = “passiveftp”;
$ftpdir = “/subdir”;$notifyemail = “webmaster@mydomain.com”; // Email which will use in case of any error.
$delbackup = 1;
$secure = 0; // If you are using secure ssl connection
$debug = 0;
?>
After that you have to create second file, which is then main backup script,
<?php
include(‘details_cp.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);
?>
Then upload these to files and just run backup_cp.php it will create the .zip file in our root directory
No comments:
Post a Comment