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.

Auto Backup Script

Discussion in 'cPanel Developers' started by CJL, Jun 29, 2009.

  1. CJL

    CJL Member

    Joined:
    Jun 20, 2009
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    Hi,

    I am sure a number of people out there use Justin Cooks backup up cron script, my question is am getting an email sent me to me once cpanel tries to run the cron job and I am not sure what it means. I am guess it means it cant access the ftp that I wont it to send the backup to, but could someone clarify this please.

    The email response from cron contains the following;
    /bin/sh: /home/username/public_html/sender.php: Permission denied


    Below is the script that I am using, is it correct? it was quiet straight forward so I assume it is;

    PHP:
    <?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 "******"// Username used to login to CPanel
    $cppass "******"// Password used to login to CPanel
    $domain "domain.com.au"// Domain name where CPanel is run
    $skin "x"// 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 "******"// Username for FTP account
    $ftppass "******"// Password for FTP account
    $ftphost "ftp.domain.com.au"// Full hostname or IP address for FTP host
    $ftpmode "ftp"// FTP mode ("ftp" for active, "passiveftp" for passive)

    // Notification information
    $notifyemail "myemail@domain.com.au"// 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);

    ?>
    Thank you.....
     
    #1 CJL, Jun 29, 2009
    Last edited by a moderator: Jun 29, 2009
  2. anoopkumar

    anoopkumar Member

    Joined:
    Feb 15, 2004
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    India
    /bin/sh: /home/username/public_html/sender.php: Permission denied

    That does not appear to be an issue with the script. Looks like you have setup the php script /home/username/public_html/sender.php wrongly in the cronjob.

    It should be like

    php /home/username/public_html/sender.php

    If you just give /home/username/public_html/sender.php, system will try to execut it as a shell script, which caused the above error.
     
  3. CJL

    CJL Member

    Joined:
    Jun 20, 2009
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    Thank you for the speedy reply anoopkumar :)

    I will give it a shot....
     
  4. CJL

    CJL Member

    Joined:
    Jun 20, 2009
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    Ok my cron job just ran now and I received this feedback via email

    X-Powered-By: PHP/5.2.9
    Content-type: text/html

    It didnt actually do anything, it was meant to perform a backup and send it to my hosting account...

    Does anyone know what the problem is???

    cheers
     
  5. mctDarren

    mctDarren Well-Known Member

    Joined:
    Jan 6, 2004
    Messages:
    664
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    New Jersey
    cPanel Access Level:
    Root Administrator
    If you don't set up the script to send the output from the PHP script to null, it will likely email it to you (you probably set up an email address when setting up the cron job, right?)

    If it didn't actually do anything, check the directory where it is running for an error_log file and see what it says is wrong.
     
  6. CJL

    CJL Member

    Joined:
    Jun 20, 2009
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    Unfortunately there was no error log present so I don’t think it was actually running what so ever for an error to occur. Therefore I made some changes to script and got the following error which tells me it is at least running. I believe this error was caused by setting the script to passiveftp. But I have changed that and rescheduled it to run later today. I will let you know how it goes.

    X-Powered-By: PHP/5.2.9
    Content-type: text/html

    <br />
    <b>Warning</b>: fsockopen() [<a href='function.fsockopen'>function.fsockopen</a>]: unable to connect to http://www.domain.com.au:2082 (Unable to find the socket transport &quot;http&quot; - did you forget to enable it when you configured PHP?) in <b>/home/username/public_html/sender.php</b> on line <b>39</b><br /> Failed to open socket connection Bailing out!
     
  7. CJL

    CJL Member

    Joined:
    Jun 20, 2009
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    Has anyone managed to get the Justin Cook backup automation script to actually work? who could advise me on what on earth is going on.

    A summary of the issues I am facing are:

    • It seems that the cron job is running but it does not seem to actually do anything. It does not do a backup and/or send it to my alternative ftp account.
    • I receive the following information in an email but I do not understand what it means.

    X-Powered-By: PHP/5.2.9
    Content-type: text/html
     
Loading...

Share This Page