The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP back up script not working

Discussion in 'Data Protection' started by John connor, Feb 5, 2015.

  1. John connor

    John connor Registered

    Joined:
    Feb 5, 2015
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    I found this site ericzhang.me/howto-cpanel-automatic-backups/ with information on how to create a back up with a cron job and a PHP file. However I am under to get this to work. The cron E-mail I get is:


    Code:
    HTTP/1.1 301 Moved
    Server: cpsrvd/11.46.0.14
    Connection: close
    Content-length: 141
    Location: /frontend/https:/backup/dofullbackup.html?submit=Generate
    Content-type: text/html; charset="utf-8"
    
    <html><head><META HTTP-EQUIV="refresh" CONTENT="5;URL=/frontend/https:/backup/dofullbackup.html?submit=Generate"></head><body></body></html>
    I'm using cPanel 11.46.0.14 as shown in the E-mail. It seems that there is a command that can't be used because something moved?

    Here is what the PHP script looks like:

    Code:
    <?php
    /*
    cPanel Backup Script
    Generated by ericzhang.me/projects/cpanel-auto-backup/
    */
    
    $auth = base64_encode("username:password");
    $domain = "162.249.125.42";
    $theme = "https://";
    $secure = true;
    $ftp = false;
    $ftpserver = "";
    $ftpusername = "";
    $ftppassword = "";
    $ftpport = "21";
    $ftpdirectory = "/";
    
    if ($secure) {
    	$url = "ssl://" . $domain;
    	$port = 2083;
    } else {
    	$url = $domain;
    	$port = 2082;
    }
    
    $socket = fsockopen($url, $port);
    if (!$socket) {
    	exit("Failed to open socket connection.");
    }
    
    if ($ftp) {
    	$params = "dest=ftp&server=$ftpserver&user=$ftpusername&pass=$ftppassword&port=$ftpport&rdir=$ftpdirectory&submit=Generate Backup";
    } else {
    	$params = "submit=Generate Backup";
    }
    
    fputs($socket, "POST /frontend/" . $theme . "/backup/dofullbackup.html?" . $params . " HTTP/1.0\r\n");
    fputs($socket, "Host: $domain\r\n");
    fputs($socket, "Authorization: Basic $auth\r\n");
    fputs($socket, "Connection: Close\r\n");
    fputs($socket, "\r\n");
    
    while (!feof($socket)) {
    	$response = fgets($socket, 4096);
    	echo $response;
    }
    
    fclose($socket);
    
    ?>
    	
    Perhaps it's the fputs($socket,?

    I don't know PHP. Any help would be great. TIA!
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
  3. GJSchaller

    GJSchaller Member

    Joined:
    Nov 5, 2012
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Reseller Owner
    I'm running into the same problem. I was using a slightly different script which failed when I migrated to PHP 5.6 - reverting back to 5.5 resolved it short term, but I would like to be on 5.6 eventually. The site for the old script appears gone, at which point I came across Eric Zhang's script - but it has the same issue.

    The error it generates is:

    HTTP/1.1 301 Moved Server: cpsrvd/11.42.1.21 Connection: close Content-length: 120 Location: https://(servername):2083/ Content-type: text/html; charset="utf-8"

    Any idea how to adjust the PHP script to account for this? The other thread mentioned above does not have a solution posted, only issues with PERL instead of PHP.
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    cPanel version 11.42 is end-of-life. Please upgrade to a supported version of cPanel at your earliest convenience and let us know if the issue persists.

    Thank you.
     
  5. GJSchaller

    GJSchaller Member

    Joined:
    Nov 5, 2012
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Reseller Owner
    Upgraded to cPanel 11.50.3, still getting the same error. The full message contains my site's URL and my offsite FTP credentials, so I will post an abbreviated version:

    HTTP/1.1 301 Moved Server: cpsrvd/11.50.3.0 Connection: close Content-length: 308 Location: ((REDACTED)) Content-type: text/html; charset="utf-8" Cache-Control: no-cache, must-revalidate Pragma: no-cache
     
  6. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
  7. GJSchaller

    GJSchaller Member

    Joined:
    Nov 5, 2012
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Reseller Owner
    Then why did you ask me to upgrade, if you're not going to support it? That was a waste of time and money on my part.
     
  8. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    There's no cost when updating your version of cPanel unless you are paying a system administrator for the task of updating it for you. It's important to use a supported version, no matter what the issue is, to ensure you have access to the newest features and previous flaws in the product are addressed. It's likely a good idea to stay at PHP 5.5 if the script works at that version, or consult with a developer to update the script:

    cPanel App Catalog :: Development Services

    Thank you.
     
  9. GJSchaller

    GJSchaller Member

    Joined:
    Nov 5, 2012
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Reseller Owner
    There was a cost incurred by my hosting company to perform the upgrade for me. In either case, it would have been more straightforward to say the script was unsupported, BEFORE asking me to upgrade and then state it was not supported.
     
Loading...

Share This Page