SolidHost Forums

SolidHost Forums (
-   Tutorials / How to? (
-   -   Cron full backup and save to remote ftp server (

dnc Jun 5th, 2005 22:57

Cron full backup and save to remote ftp server
Here is a script I use successfully for more than 5 months. I found it somewhere in the net and it is really great.

PHP Code:


// PHP script to allow periodic cPanel backups automatically.
// Based on script posted by max.hedroom in forums
//   This script contains passwords.  KEEP ACCESS TO THIS FILE SECURE!


// Info required for cPanel access
$cpuser "user"// Username used to login to CPanel
$cppass "pass"// Password used to login to CPanel
$domain ""// 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 host
$ftpuser "ftp_user"// Username for FTP account
$ftppass "ftp_pass"// Password for FTP account
$ftphost "ftp_host"// Full hostname or IP address for FTP host
$ftpmode "ftp"// FTP mode ("ftp" for active, "passiveftp" for passive)

// Notification information
$notifyemail ""// Email address to send results

// Secure or non-secure mode
$secure 0// 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;


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=$ftpmode&email=$notifyemail&server=$ftphost&user=$ftpuser&pass=$ftppass&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");

// Grab response even if we don't do anything with it.
while (!feof($socket)) {
$response fgets($socket,4096);
  if (
$debug) echo $response;



I have a question for the SH admin:
- is it better to use ftp or passive ftp for the tranfer on the remote host? Speaking of speed and mainly on load on the server.

CPUBum Jul 1st, 2005 16:07

This is nice... I will have to try it out and see if it will FTP to my home location for some of my critical sites... Even though I backup to a seperate drive in my server, still nice to have another backup elsewhere

CPUBum Oct 26th, 2005 15:03

Another way to do remote backups is to create a script that runs /scripts/pkgacct $1 where $1 is the accout you want backed up. This will create a tar of the entire site that can be placed into the /home directory and restored from WHM ROOT. It packages up everything you need to do a complete restore. In the script have it FTP the file to another remote location. Then you just cron the script that does this backup and FTP. That way you do not need to have any passwords or user ID's sitting in files on the server that in text format.

Alexanderjhon Mar 23rd, 2010 08:47

I have been reading through your site, finding it very interesting.

All times are GMT +2. The time now is 17:07.

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.