[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 517
  • Last Modified:

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?
0
mpaert
Asked:
mpaert
  • 2
  • 2
  • 2
  • +2
1 Solution
 
Wooky JackCommented:
Are you on your own setup or through a hosting company?
0
 
mpaertAuthor Commented:
I've got my own setup with ssh access
0
 
mherCommented:
i can give you a php script that you can run by cron and it will do what you asked for.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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?
0
 
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";
?>
0
 
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
0
 
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
0
 
GranModCommented:
PAQed with no points refunded (of 500)

GranMod
Community Support Moderator
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now