1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Rep Power

    I'm trying to write what I thought would be a simple script to backup a MySQL database on a remote server.

    I borrowed the following code from another message posted here http://www.devshed.com/Talk/Forums/F...ML/002295.html

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $command = "`mysqldump -h localhost -u user -pPasword db_name > backupdir/newbackup.sql`";
    if (exec($command) == 0) { echo "Backup Succesful";
    } else { echo "Backup failed";

    echo $command;


    I can get the mysqldump to work from the command line (thanks to help from rod k), but it won't run from the script. I have tried endless varieties of exec(), passThru(), virtual(), and backticks, but to no avail.

    I can successfully execute simple commands like ls -l from within the php script, but I just can't seem to get this mysqldump working. Can anyone point out what I'm doing wrong?

    Cross-eyed and almost bald,
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Niagara Falls (On the wrong side of the gorge)
    Rep Power
    Are you sure it isn't working? exec() returns the last output from the command. mysqldump doesn't return anything if it's successful so if exec($command)==0 is never going to evaluate true.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Rep Power
    After more trial and error, I finally found that it's a permission problem. For some reason I can run mysqldump through telnet, but not as a web user. I guess I assumed that, since I can run MySQL queries from a web page, I would be able to run mysqldump as well.

    Miles to go, and lots more to learn.

    Thanks for your help!
  6. #4
  7. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Caro, Michigan
    Rep Power
    So did you get it to work by changing around permissions?

    If not, you could also use


    That'll save your data as a tab delimited file, but it doesn't save your table definitions. To load it back into your table, you use


    I like mysqldump better, but if you can't get it to work, then this might be a viable alternative.

    Or, maybe you could have a cron job run every so often to do mysqldump for you? I'm not to familiar with cron though....

    ---John Holmes...

    The manual can probably answer 90% of your questions.

    PHP Manual: <A HREF="http://www.php.net/manual
    MySQL" TARGET=_blank>http://www.php.net/manual
    MySQL</A> Manual: <A HREF="http://www.mysql.com/documentation/mysql/bychapter/
    ************************" TARGET=_blank>http://www.mysql.com/documentation/mysql/bychapter/

Similar Threads

  1. Mysql problem.
    By Nik in forum MySQL Help
    Replies: 54
    Last Post: December 21st, 2006, 06:02 PM
  2. script to backup mysqldatabase
    By csross in forum Scripts
    Replies: 5
    Last Post: July 28th, 2004, 06:47 PM
  3. php script won't work inside "cgi-local" directory
    By Volitics in forum PHP Development
    Replies: 5
    Last Post: April 26th, 2004, 10:50 PM
  4. Mysql backup
    By kajic in forum PHP Development
    Replies: 4
    Last Post: February 11th, 2004, 04:48 PM
  5. how to make perl script work?
    By gencoglu in forum Perl Programming
    Replies: 1
    Last Post: February 9th, 2004, 12:35 PM

IMN logo majestic logo threadwatch logo seochat tools logo