Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Backup using Cron and a backup script fails on Security Token

Discussion in 'Data Protection' started by caylean, Jan 15, 2015.

  1. caylean

    caylean Active Member

    Joined:
    Jul 2, 2013
    Messages:
    27
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hello together,
    I have for my personal sites a small shared hosting and no access to the WHM Backup Config. But I still want to have my personal Backup files on a seperate Backup VPS Server.
    The VPS was easily configured and is right now used with SFTP Access (Maybe also already a Problem, but couldn't figure that out so far, as i would plainly install vsftpd and i would be good to go.

    I have created on for my Accounts a Cronjob as seen below

    0 0 * * 0 php -f /home/ACCOUNT/public_html/backup/backup.php
    The Path i was given by my Hoster as i had asked him directly the ecact Path i would need to use in order to get the script running.

    where i use the Script i have created using the Guide here:
    /http://www.ericzhang.me/howto-cpanel-automatic-backups/

    Code:
    <?php
    
    $auth = base64_encode("ACCOUNTNAME:PASSWORD);
    $domain = "name.hostname.com";
    $theme = "x3";
    $secure = true;
    $ftp = true;
    $ftpserver = "123.456.789.012";
    $ftpusername = "VPSUSERNAME";
    $ftppassword = "VPSUSERPW";
    $ftpport = "VPS_SSH_PORT";
    $ftpdirectory = "/home/VPSUSERNAME/Backupfolder";
    
    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);
    
    ?>
    
    For testing purpose i had ran the Cron every 2 minutes and send the result by mail to see if it was successful..... Well, it was not.

    Code:
     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    HTTP/1.1 401 Access Denied
    Set-Cookie: cprelogin=no; HttpOnly; path=/; port=2083; secure
    Set-Cookie: cpsession=%3aO_zJdMMvTcG3s2w[.Shortened.]8a2949637881e80; HttpOnly; path=/; port=2083; secure
    Server: cpsrvd/11.46.2.0
    Content-type: text/html; charset="utf-8"
    Connection: close
    Date: Fri, 16 Jan 2015 05:02:02 GMT
    Content-Length: 21107
    
    
    <!DOCTYPE html>
    <html dir="ltr">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="google" content="notranslate" />
        <title>cPanel Login</title>
        <link rel="shortcut icon" href="/cPanel_magic_revision_1372453550/unprotected/cpanel/favicon.ico" />
    
        <!-- EXTERNAL CSS -->
        <link href="/cPanel_magic_revision_1372453527/unprotected/cpanel/style_v2_optimized.css" rel="stylesheet" type="text/css" />
    
        <!--[if IE 6]>
        <style type="text/css">
            img {
                behavior: url(/cPanel_magic_revision_1372453485/unprotected/cp_pngbehavior_login.htc);
            }
        </style>
        <![endif]-->
    
        <script>
        window.DOM = { get: function(id) { return document.getElementById(id) } };
        </script>
    </head>
    <body>
     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    Properbly it is the Security Token (cpsess) that gets generated each time you login.

    Is there any other Script that would help me here, because i believe rewriting this one is for me way out of my possibilities as I have not the sligtest idea of it, I do not even understand how it does what it was supposed to do ;)

    Help with that matter would be highly welcome!
     
  2. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,802
    Likes Received:
    1,895
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello :)

    You may find the following thread helpful, as there's discussion of a similar topic with links to potential solutions:

    Backing Up cPanel Accounts

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. caylean

    caylean Active Member

    Joined:
    Jul 2, 2013
    Messages:
    27
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Wow THANKS Michael,
    had searched here already, but couldn't find any solution.
    So properbly this one here can closed if there really is a solution, then i do not need to mess here with a non working script around ;)
     
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice