Home   >>   Webhosting   >>   How To Automate Full Backup on cPanel
How To Automate Full Backup on cPanel PDF Print E-mail
( 2 Votes )
How To - Webhosting
Written by Christian Foronda   
Friday, 08 October 2010 09:38

Upload the script on /home/YourAccount/ (NOT /home/YourAccount/public_html/):

Create the script fullbackup.php:

	<?php
	// Info required for cPanel access
	$cpuser = "username";
	$cppass = "password";
	$domain = "example.com";
	$skin = "x3";

	// Notification information
	$notifyemail = "YourEmailAddress";

	// Secure or non-secure mode
	$secure = 1;

	// Set to 1 to have web page result appear in your cron log
	$debug = 0;

	// ** NO EDIT BELOW THIS LINE ***

	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=homedir&email=$notifyemail&server=&user=&pass=&port=&rdir=";

	// Make POST to cPanel
	fputs($socket,\
	"POST /frontend/".$skin."/backup/dofullbackup.html?".$params." HTTP/1.0\r\n");
	fputs($socket,"Host: $domain\r\n");
	fputs($socket,"Authorization: Basic $pass\r\n");
	fputs($socket,"Connection: Close\r\n");
	fputs($socket,"\r\n");

	// Grab response even if we don't do anything with it.
	while (!feof($socket)) {

	$response = fgets($socket,4096);

	if ($debug) echo $response;
	}
	fclose($socket);
	?>

Schedule the script to run regularly on cPanel's cron tool:

	15 2 * * * /usr/local/bin/php /home/YourAccount/fullbackup.php
	(Runs every night at 2:15 a.m.)

If the above cron doesn't work. Change the path of the php:

	15 2 * * * /usr/bin/php5 /home/YourAccount/fullbackup.php

Reference:
http://lgallardo.com




blog comments powered by Disqus
Last Updated on Friday, 08 October 2010 12:03