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.

custom backup script

Discussion in 'General Discussion' started by SetLar8, Feb 24, 2006.

  1. SetLar8

    SetLar8 Well-Known Member

    Joined:
    Mar 5, 2004
    Messages:
    60
    Likes Received:
    0
    Trophy Points:
    6
    Hi,

    Can anyone tell me if there is a script that will allow me to create a cpmove or full backup for a specified user on a server?

    If not how can i integrate SSH commands within php,

    e.g.

    /scripts/pkgacct username

    Thanks.
     
  2. elleryjh

    elleryjh Well-Known Member

    Joined:
    Apr 12, 2003
    Messages:
    479
    Likes Received:
    0
    Trophy Points:
    16
    the exec function will run any command. Of couse this script must be run by root.

    PHP:
    <?

    // run a backup on the given username and return a string of the output
    function runbackup($username){
          
    $output = array();
          
    exec("/scripts/pkgacct $username"$output);
          return 
    implode("\n"$output);
    }

    ?>
     
  3. SetLar8

    SetLar8 Well-Known Member

    Joined:
    Mar 5, 2004
    Messages:
    60
    Likes Received:
    0
    Trophy Points:
    6
    Hi, i have tried this command and i get the following output:

    pkgacct started.
    pkgacct version 4.1 - running with uid 99
    using time::hires for speedups

    Unable to find domain name for example


    I have the owner of the php page set to root on the server, is there anything else i must do to get this to run?

    P.S. the user example is not a real user but i has been tested with many other users on the server.

    Thanks.
     
  4. elleryjh

    elleryjh Well-Known Member

    Joined:
    Apr 12, 2003
    Messages:
    479
    Likes Received:
    0
    Trophy Points:
    16
    UID 99 as it says in the output is probably nobody, which your php scripts run as.


    I would suggest not running it through a webpage. Instead, use a cron job or manual entry at the command line to run the backup.

    If you must run from the web server:
    Your php scripts runs as apache, but you must run as root. Having the file owned by root is not enough.

    so, you'll have to create one php/perl file owned by root with the setuid bit enabled (chmod u+s) and call it from the php script that runs from the webserver. It's a somewhat complicated process and very dangerous if you don't do it right - so i wouldn't recommend it unless you know exactly what you're doing.
     
  5. SetLar8

    SetLar8 Well-Known Member

    Joined:
    Mar 5, 2004
    Messages:
    60
    Likes Received:
    0
    Trophy Points:
    6
    If i can find out how to use this then i will be having a php page that will run on a cronjob daily and if i has selected a backup on a certain date then this will be done.

    I just need to know how to make this happen with a php page at first, if i was to use it with a cronjob does that automatically run as root? if not how do i set it up to do so?

    Thanks alot for your help.
     
  6. elleryjh

    elleryjh Well-Known Member

    Joined:
    Apr 12, 2003
    Messages:
    479
    Likes Received:
    0
    Trophy Points:
    16
    I have breifely explained how to do it as a php page and said that I don't recommend it. If you must have it that way, hire a professional who knows about security to do it for you.

    To run as a cronjob, add it to the root's crontab with "crontab -e", and it will be run as root.
     
Loading...

Share This Page