Re: exec problem
| From: | Richard Lynch | Date: | Wed, 01 Aug 2001 06:45:58 +0000 |
| Subject: | Re: exec problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-60586@lists.php.net to get a copy of this message | ||
> Hi I'm trying to create a script which my cron will run once a day to
backup
> my MySQL database, but the exec command doesn't want to work no matter
what I
> try...
Uhhhhh.
cron + PHP is cool, but using cron to run PHP to run mysqldump is kinda
silly... :-)
Just put the mysqldump line in your cron job, or create a "shell script" to
do what you need.
Basically, a shell script:
1. Starts with
#!/usr/bin/sh
(You can use any "shell" [bash, csh, ash, smrsh] instead of sh that feels
good.]
2. Has stuff you would normally type on the command line, like:
mysqldump -h localhost -u user -p pass --opt DataBase > BACKUPS/backup.mysql
3. Has permission to be run by one or more users:
chmod 700 backup.sh
You can then use /path/to/backup.sh as a command, or use that in a cron job.
> exec("mysqldump -h localhost -u user -p pass --opt DataBase >
> BACKUPS/backup.mysql") or die("Problem");
>
> I have tried adding the full path to mysqldump,
You need that.
> I have tried using my root
> access,
machine root, or MySQL root? The former is a BAD IDEA... The latter ain't
so hot either. Certainly don't be putting a script with database passwords
in your web-tree.
> I have tried using a different dir to store the files, changed
> permissions all sorts and nothing works. It always returns "Problem" and
if I
> take out the or die then it just returns a blank screen.
You can add more args to exec() to get more info about what went
wrong/right:
exec("...", $results, $errorcode);
while (list(,$line) = each($results)){
echo $line, "<BR>\n";
}
if ($errorcode){
echo "OS Error: $errorcode. Usually paths/permissions. Use 'man errno'
to look it up.<BR>\n";
}