1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

how to make automatic backup in cpanel

Discussion in 'Site & Server Administration' started by RECEP, Apr 1, 2010.

  1. #1
    hello, l have a host service in hostgator with cpanel. l am curiouse if its possible to make automatic backups without payning to hostgator.
    is there a script that makes backup of my files and database... ?;)
     
    RECEP, Apr 1, 2010 IP
  2. mnvlxxx

    mnvlxxx Peon

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Create a file named fullbackup.php on the home folder of your account with this code (modify the Cpanel and FTP user and password to yours):
    <?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
    $cpuser = "user"; // Username used to login to CPanel
    $cppass = "password"; // Password used to login to CPanel
    $domain = "domain.com"; // Domain name where CPanel is run
    $skin = "x3"; // Set to cPanel skin you use (script won't work if it doesn't match). Most people run the default x theme
    
    // Info required for FTP host
    $ftpuser = "user"; // Username for FTP account
    $ftppass = "password"; // Password for FTP account
    $ftphost = "host"; // Full hostname or IP address for FTP host
    $ftpmode = "ftp"; // FTP mode ("ftp" for active, "passiveftp" for passive)
    
    // Notification information
    $notifyemail = "your@email.com"; // 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;
    
    // *********** 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… 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");
    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);
    
    ?>
    PHP:
    Then create a cron job like this one:
    15  	1  	*  	*  	*  	 /usr/local/bin/php /home/yourcpaneluser/fullbackup.php
    Code (markup):
    This will make a full backup everyday and place it on an ftp server at 1:15 am.
     
    mnvlxxx, Apr 1, 2010 IP
    micksss likes this.
  3. vahsi000

    vahsi000 Well-Known Member

    Messages:
    706
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    140
    #3
    that's a really neat script mnvlxxx, thanks for the share.

    also, just to let you know recep, hostgator automatically backs up your data on a weekly basis

    Finally, it's nice to see more and more turks are joining DP forums ;)
     
    vahsi000, Apr 1, 2010 IP
  4. micksss

    micksss Notable Member

    Messages:
    4,427
    Likes Received:
    268
    Best Answers:
    1
    Trophy Points:
    285
    #4
    Great script mnvlxxx and very kind of you to share it. Does it put the backup in the home directory?
     
    micksss, Apr 1, 2010 IP
  5. mnvlxxx

    mnvlxxx Peon

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I usually put the backups on a independant server but you can place them on home folder directory too. Basically the script makes the login in CPanel and then automatically submits the form on the selected page (in this case "/backup/dofullbackup.html"). I think most features of Cpanel can be used like that. Already tried it for automatic subdomain and database creation a works very well.
     
    mnvlxxx, Apr 1, 2010 IP
  6. Danjames

    Danjames Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I couldn't get this script to work properly. It appears hostgator just made a few changes to what it wants on the form submission. Here are the few changes I made and now it appears to be working. I added an input for the ftp directory and edited the query string parameters to work. Posting the code just to hopefully save someone else time in the future.

    
    <?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
    $cpuser = "user"; // Username used to login to CPanel
    $cppass = "pass"; // Password used to login to CPanel
    $domain = "domain"; // Domain name where CPanel is run
    $skin = "x3"; // Set to cPanel skin you use (script won't work if it doesn't match). Most people run the default x theme
    
    
    // Info required for FTP host
    $ftpuser = "user"; // Username for FTP account
    $ftppass = "pass"; // Password for FTP account
    $ftphost = "server"; // Full hostname or IP address for FTP host
    $ftpmode = "ftp"; // FTP mode ("ftp" for active, "passiveftp" for passive)
    $dir = "/";     // Directory to put the backup in
    
    
    // Notification information
    $notifyemail = "email"; // 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;
    
    
    // *********** 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… Bailing out!\n"; exit; }
    
    
    // Encode authentication string
    $authstr = $cpuser.":".$cppass;
    $pass = base64_encode($authstr);
    
    
    $params = urlencode("dest=" . $ftpmode . "&email_radio=1&email=" . $notifyemail . "&server=" . $ftphost . "&user=" . $ftpuser . "&pass=" . $ftppass . "&port=21&rdir=" . $dir . "&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);
    
    
    ?>
    Code (markup):
     
    Danjames, Nov 2, 2011 IP
  7. amgadhs

    amgadhs Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks mnvlxxx for sharing the script :) Saved me a lot research and development time.
     
    amgadhs, Nov 2, 2011 IP
  8. B.Money

    B.Money Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Anyone have another update on this? No longer works for hostgator it seems. Cron runs, but the address must not be working correctly because no backup is made.
     
    B.Money, Jun 27, 2012 IP
  9. livetecshosting

    livetecshosting Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    livetecshosting, Jun 29, 2012 IP
  10. Hostwinds_Dan

    Hostwinds_Dan Active Member

    Messages:
    149
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #10

    You need to make sure the links are correct here, hostgator seems to change things up to prevent scripts like this from working. Although recently they were bought out by EIG; who knows what practices are in store now.
     
    Hostwinds_Dan, Jun 29, 2012 IP
  11. xengine

    xengine Greenhorn

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #11
    A script I wrote and used for db backup: easycronblog.blogspot.com/2011/11/php-to-backup-mysql-database.html
     
    xengine, Jul 22, 2012 IP