cpanel ftp backup question

Is it possible to run 1 command in SSH and have all my cpanel accounts backed up separately to an FTP location?
mpaertAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wooky JackCommented:
Are you on your own setup or through a hosting company?
mpaertAuthor Commented:
I've got my own setup with ssh access
mherCommented:
i can give you a php script that you can run by cron and it will do what you asked for.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

mpaertAuthor Commented:
yes please, thatwould be great. So, would i just put the php scrip on my space, and run a cron job (dont' exactly know how to set it up) to run the php file?
mherCommented:
<?php
  /*
   
  What this script does:
  It will backup all accounts under a cPanel Reseller Account
     
  How it works:
  Reads all accounts (domain and username specifically) from the listaccts page in WHM
  Calls the dofullbackup.html routine of cpanel for each account,
    using the account's username and the reseller's password
  Creates filenames like "backup-mm-dd-yyyy-hh-mm-ss-mydomain_com.tar.gz"
  Saves the backup file to an ftp destination if specified
   
  Caveats:
  This script doesn't require cron, but can be executed from one.
   
  Instructions:
  1. Modify "config" variables below, to suit
  2. From the command prompt:
      >php /www/cgi-bin/Backup_reseller.php
  3. ([Or] Optionally) Set up a cron job to call this script
   
  */
   
  /*** BEGIN CONFIG ***/

  // Reseller Domain (e.g. myDomain.com), UserID and Password
  $whmDomain  = '70.83.64.106'; //your reseller domain or ip
  $whmUser    = 'user'; //your web host manager user name
  $whmPass    = 'pass'; //your web host manager password

  // Destination; Same as offered within cPanel; Choose your poison...
  //  $dest = 'homedir'; //Home Directory
  //  $dest = 'ftp'; //Remote FTP Server
  $dest = 'passiveftp'; //Remote FTP Server (Passive mode transfer)
 
  // Skin used in cPanel
  $skin = 'monsoon'; //cpanel skin in use

  // Email to send completion notification eMail
  $email = 'blah@blah.net';

  // Backup FTP Domain (e.g. myDomain.com), UserID and Password  
  $server = 'backup15.gnax.net'; // Remote Server (FTP/SCP only)
  $user = 'user2'; // Remote User (FTP/SCP only)  
  $pass = 'pass2'; // Remote Password (FTP/SCP only)

  // Be kind to your kindred...  Take a nap!
  $sleep = 90; // How many seconds to pause between each account
   
  // BackUp the Reseller Domain too?
  $bkupReseller = false; // Set to 'true' to backup the reseller's account,
                        //       'false' to skip the reseller's account
     
  /*** END CONFIG ***/

   
  set_time_limit(0);
  echo ">> Reseller Full Backup <<\n";
   
  // Base64 Encode Reseller UserID & Password
  $authstr = "$whmUser:$whmPass";
  $whmUidPass = base64_encode($authstr);
           
   
  // Get the WHM 'list accounts' page
  $socket = fsockopen($whmDomain,2086,$errno,$errstr);
  if (!$socket) {
     echo "fsockopen Error to WHM: $errstr ($errno)<br />\n";
     die();
  } else {
    fputs($socket,"GET /scripts2/listaccts?viewall=1\r\n");
    fputs($socket,"HTTPS/1.0\r\n");
    fputs($socket,"Host: $whmDomain\r\n");
    fputs($socket,"Authorization: Basic $whmUidPass \r\n");
    fputs($socket,"Connection: close\r\n\r\n");
     
    $page = '';
    while (!feof($socket)) {
      $page .= fgets($socket,4096);
    }
    fclose($socket);
  }
   
  // Get each account's table row
  $int2 = preg_match_all("/<tr class=(?:tdshade2|tdshade1)>(.*?)<\/tr>/is", $page, $matches);

  if($int2 > 0 && is_array($matches[1])) {
      foreach($matches[1] as $match) {        
          $account = explode('</td><td>',$match);
          $account[0] = strip_tags(trim($account[0])); //domain
          $account[2] = strip_tags(trim($account[2])); //username
       
          // Base64 Encode Account UserID w/ Reseller Password
          $authstr = "$account[2]:$whmPass";
          $cPanelUidPass = base64_encode($authstr);
           
          // Kick off the cPanel Backup for the Account...
          $socket = fsockopen($account[0],2082,$errno,$errstr);
          if (!$socket) {
             echo "fsockopen Error: $errstr ($errno)\n";
          } else {
            echo "Processing client account: $account[0] \n";
            fputs($socket,"GET /frontend/$skin/backup/dofullbackup.html?dest=$dest&email=$email&server=$server&user=$user&pass=$pass\r\n");
            fputs($socket,"HTTPS/1.0\r\n");
            fputs($socket,"Host: $account[0] \r\n");
            fputs($socket,"Authorization: Basic $cPanelUidPass \r\n");
            fputs($socket,"Connection: close\r\n\r\n");
             
            while (!feof($socket)) {
              fgets($socket,4096);
            }
            fclose($socket);
          }
          sleep($sleep);
        }
  }
   
  // Now do yourself if desired...
  if($bkupReseller){
    // Kick off the cPanel Backup for the Reseller Account...
    $socket = fsockopen($whmDomain,2082,$errno,$errstr);
    if (!$socket) {
       echo "fsockopen Error: $errstr ($errno)\n";
    } else {
      echo "Processing reseller account: $whmDomain \n";
      fputs($socket,"GET /frontend/$skin/backup/dofullbackup.html?dest=$dest&email=$email&server=$server&user=$user&pass=$pass\r\n");
      fputs($socket,"HTTPS/1.0\r\n");
      fputs($socket,"Host: $whmDomain \r\n");
      fputs($socket,"Authorization: Basic $whmUidPass \r\n");
      fputs($socket,"Connection: close\r\n\r\n");
       
      while (!feof($socket)) {
        fgets($socket,4096);
      }
      fclose($socket);
    }
  }
  echo ">> Le Fini <<\n\n";
?>
Jeffrey Kane - TechSoEasyPrincipal ConsultantCommented:
mpaert,

What you are asking for is available in CPanel's WebHostManager.  You state, "I've got my own setup with ssh access", but do you have access to WHM??  Because it's quite easy to configure this through WHM.

Whoever your hosting provider is would just need to designate you as a reseller in order to provide WHM access to your accounts.

Jeff
TechSoEasy
Jeffrey Kane - TechSoEasyPrincipal ConsultantCommented:
Sorry, but that script is not necessary.  It requires that he has access to WHM, which if he does, then all he needs to do is configure the ftp backup within WHM.

Jeff
TechSoEasy
GranModCommented:
PAQed with no points refunded (of 500)

GranMod
Community Support Moderator

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Networking

From novice to tech pro — start learning today.