Zubrag.com
March 18, 2019, 08:28:30 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Automatic Hosting Account Backups  (Read 3593 times)
smithster
Web Trade Pro
Newbie
*
Posts: 27


WWW
« on: February 04, 2009, 06:21:55 PM »

Hi guys, I came across a script which automatically backs up your hosting account for you upon executing the script.  I have made a few adjustments to it, more so because I wanted to set up a cron job to execute the script for me.

I find it's a good idea to have more than 1 backup, I actually have a weeks worth of backups in place, and I backup twice daily too.  After setting up my cron job, my sites are now backed up twice daily without me being there!

Here's the script...
Code:
<?php
// PHP script to allow periodic cPanel backups automatically, optionally to a remote FTP server.
// This script contains passwords.  KEEP ACCESS TO THIS FILE SECURE! (place it in your home dir, not /www/)
// ********* THE FOLLOWING ITEMS NEED TO BE CONFIGURED *********

// Info required for cPanel access
// Domain 1
$sites['1']['cpuser'] = "username"// Username used to login to CPanel
$sites['1']['cppass'] = "password"// Password used to login to CPanel
$sites['1']['domain'] = "domain.com"// Domain name where CPanel is run
$sites['1']['skin'] = "x"// Set to cPanel skin you use (script won't work if it doesn't match). Most people run the default x theme

// Domain 2
/*$sites['2']['cpuser'] = "username2";
$sites['2']['cppass'] = "password2";
$sites['2']['domain'] = "domain2.com";
$sites['2']['skin'] = "rvlightblue";

// Domain 3
$sites['3']['cpuser'] = "username3";
$sites['3']['cppass'] = "password3";
$sites['3']['domain'] = "domain3.com";
$sites['3']['skin'] = "x3";*/

// Info required for FTP host
$day strtolower(date('l'));
$time date('a'time());

if(
$time == 'am')
{
$ftpuser $day.'1';
$ftppass $day.'1';
}
else
{
$ftpuser $day.'2';
$ftppass $day.'2';
}
$ftphost "ftp_address"// Full hostname or IP address for FTP host
$ftpmode "ftp"// FTP mode ("ftp" for active, "passiveftp" for passive, or "scp" for scp - most secure)
$ftpdir ''// Directory to save the files in

// Notification information
$notifyemail "sc-clan@hotmail.co.uk"// 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 *********
foreach ($sites as $site) {
  if (
$secure) {
 $url "ssl://".$site['domain'];
 $port 2083;
  } else {
 $url $site['domain'];
 $port 2082;
  }
  
$socket fsockopen($url,$port);
  if (!
$socket) { echo "Failed to open socket connectionů Bailing out!\n"; exit; }
  
// Encode authentication string
  
$authstr $site['cpuser'].":".$site['cppass'];
  
$pass base64_encode($authstr);
  
$params "dest=$ftpmode&email=$notifyemail&server=$ftphost&user=$ftpuser&pass=$ftppass&port=&rdir=$ftpdir&submit=Generate Backup";
  
// Make POST to cPanel
  
fputs($socket,"POST /frontend/".$site['skin']."/backup/dofullbackup.html?".$params." HTTP/1.0\r\n");
  
fputs($socket,"Host: {$site['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;
  }
  echo 
"\nDone with {$site['domain']}\n";
  
fclose($socket);
}
?>

Basically I have set up some FTP accounts, two for each day of the week and one for am and one for pm, so for example, monday1, monday2, tuesday1, tuesday2, and so on...

The script works out what day of the week it is and what time period, am or pm, and then sets the username and password for FTP access accordingly.  So if it's 9 in the morning on monday, the username and password will be monday1 and monday1.  This way the ftp server can tell the web server which directory to upload to.

Very simple.

Hope it helps Smiley

Smithster

Logged

S
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC