SetLar8

Well-Known Member
Mar 5, 2004
60
0
156
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.
 

elleryjh

Well-Known Member
Apr 12, 2003
475
0
166
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);
}

?>
 

SetLar8

Well-Known Member
Mar 5, 2004
60
0
156
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.
 

elleryjh

Well-Known Member
Apr 12, 2003
475
0
166
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.
 

SetLar8

Well-Known Member
Mar 5, 2004
60
0
156
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.
 

elleryjh

Well-Known Member
Apr 12, 2003
475
0
166
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.