Hi there,
Just noticed how nice cnapel will backup my entire user (email, DB, web files, logs etc.) and upload it to my own server! So I started looking at how to add this fullbackup to my crontab. Unfortunately it is a form that has to be filled and it is not easy to do with simple unix command. So using an old cpanel script I ended up with this one, that will login to cpanel for you, start the backup and upload it to wherever you requested:
http://joro.geodar.com/diary/2005/11/11/233 is the URL and the script is in PHP:
< ?php
// PHP script to allow periodic cPanel backups automatically.
// Based on script posted by max.hedroom in cpanel.net forums
// This script contains passwords. KEEP ACCESS TO THIS FILE SECURE!
// It is updated to support secure ftp connections and remote directories
// ********* THE FOLLOWING ITEMS NEED TO BE CONFIGURED *********
// Info required for cPanel access
$cpuser = "username"; // Username used to login to CPanel
$cppass = "password"; // Password used to login to CPanel
$domain = "www.host.com"; // Domain name where CPanel is run
$skin = "x"; // Set to cPanel skin you use (script won't work if it doesn't match)
// Info required for FTP/SFTP host
$ftpuser = "sshusername"; // Username for FTP(SCP) account
$ftppass = "sshpassword"; // Password for FTP(SCP) account
$ftphost = "sshhost"; // Full hostname or IP address for FTP(SCP) host
$ftpmode = "scp"; // FTP mode ("ftp" for active, "passiveftp" for passive, "scp" for secure ftp)
$ftpport = "22"; // PORT for FTP(SCP) host
$ftprdir = "/path/to/directory"; //Remote Directory on SCP host
// Notification information
$notifyemail = "mailto@somehost.com"; // Email address to send results
// Secure or non-secure mode
$secure = 1; // 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 = 0;
// *********** NO CONFIGURATION ITEMS 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!\n"; exit; }
// Encode authentication string
$authstr = $cpuser.":".$cppass;
$pass = base64_encode($authstr);
$params = "dest=$ftpmode&email=$notifyemail&server=$ftphost&user=$ftpuser&pass=$ftppass&port=$ftpport&rdir=$ftprdir&submit=Generate Backup";
// 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);
?>
Just save the code in a file, edit the variables to reflect your own data and execute from anywhere with: php nameoffile.php
so I added to my own crontab :
00 02 * * * /usr/bin/php /path/to/my/phpfile.php >/dev/null
and every day at 2 local time I start a backup of my entire username. and in about an hour (depending on the speed and size of your directory this time will vary) I have something like :
backup-MM.DD.YY_HH-MM-SS_myusername.tar.gz
in the directory I've specified in the file.
For any problems you can mail me or post here.
P.S. If admins think it is OK, they can put this post in the How-to's section. I guess that's the right place for it to be.
Enjoy