user431806
user431806

Reputation: 416

PHP exec() and filesystem permissions

So im new to exec and recently wanted to auutomate mysql Dumping via a php script.

My php file originates from

var/WWW/html/tool/script.php

The folder reads root / WWW-data when i do ls -l

It is doing

exec('mysqldump -user=user --password=pass db > selfDir\dump.sql')

Now what i would expect is the for the script to output to dump.sql inside the scripts Folder. This is not Happening though.

Only once i did touch dump.sql and chmod 777 dump.sql was the dump actually being written.

I dont understand why. How can i alter my exec() to make sure it can CREATE the dump.file instead of only writing to it once it already exists ?

thanks

Upvotes: 0

Views: 253

Answers (1)

Guillem Perez
Guillem Perez

Reputation: 266

If you only want to automatize the database backup, it's better calling the mysqldump with any other system service, like cron.

Rely on php exec can generate too many errors.

  • Php limit time execution
  • Execute from request, then the request is killed the exec is killed or need to wait all the mysqldump time
  • More difficult permissions
  • Limitation memory in php and the server

In cron you the backup will be (example from The Java Guy):

0 0 * * * mysqldump -u 'username' -p'password' DBNAME > /home/eric/db_backup/liveDB_`date +\%Y\%m\%d_\%H\%M`.sql

Other link for crontab backup with mysql: Answer K1773R mysql-dump-cronjob

Upvotes: 2

Related Questions