SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    SitePoint Addict AHMED's Avatar
    Join Date
    Oct 2002
    Location
    Egypt
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysqldump doesn't work .. why ?

    hi all .. i ve a simple php script to backup a mysql db like this :
    PHP Code:
           exec('mysqldump -h localhost -u mofadla_ahmed -p ahmed favorite > db.sql') or die(mysql_error());
            echo 
    "<meta http-equiv='refresh' content='1; Url=db.sql'>"
    it gives no error but when i try it on windows it gives and empty file and on linux does'nt give an error also but doesn't create any file ..

    i ve searched the forum but all threads was about backing up many databases and all of them doesn't work with me

    also im sure about the write permissions of both systems

    so can any body help ?

  2. #2
    SitePoint Addict AHMED's Avatar
    Join Date
    Oct 2002
    Location
    Egypt
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    any idea?
    Last edited by AHMED; Apr 30, 2004 at 07:45.

  3. #3
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might consider storing the backup on your sever and then downloading it from there.

    This is the current script I use with a cron job:

    PHP Code:
    include('db_login.php');

    // Mysql Database Information:
        
    $database 'db';   // name of the database.
        
    $username $user;  // username with access to database.
        
    $password $pass;  // password for username.

    // Database Backup Filename & Location
        
    $backupto '/home/citasvir/sql_backups';  // absolute path to folder containing database - no trailing slash.
        
    $backupas $database '.sql.' date "Ymd" ) . '.gz';

    // Perform backup
    $backupcommand "mysqldump -u$username -p$password $database | gzip >$backupto/$backupas";

    passthru ("$backupcommand"$error);
    if(
    $error) {
       echo (
    "Problem: $error\n"); exit;

    Community Guidelines | Community FAQ

    "He that is kind is free, though he is a slave;
    he that is evil is a slave, though he be a king." - St. Augustine

  4. #4
    SitePoint Addict AHMED's Avatar
    Join Date
    Oct 2002
    Location
    Egypt
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it gives : Problem: 127

    what does this mean ?

  5. #5
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you change the permissions for the directory where you are storing the backup file? It needs to be changed to 777.
    Community Guidelines | Community FAQ

    "He that is kind is free, though he is a slave;
    he that is evil is a slave, though he be a king." - St. Augustine

  6. #6
    SitePoint Addict AHMED's Avatar
    Join Date
    Oct 2002
    Location
    Egypt
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i did and it still makes the same error

  7. #7
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you paste the script with your modifications?
    Community Guidelines | Community FAQ

    "He that is kind is free, though he is a slave;
    he that is evil is a slave, though he be a king." - St. Augustine

  8. #8
    SitePoint Addict AHMED's Avatar
    Join Date
    Oct 2002
    Location
    Egypt
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:

    <?php
    // Mysql Database Information:
        
    $database 'mofadla_favorite';   // name of the database.
        
    $username "mofadla_ahmed";  // username with access to database.
        
    $password "ahmed";  // password for username.
    // Database Backup Filename & Location
        
    $backupto '/home/mofadla/public_html/test/db';  // absolute path to folder containing database - no trailing slash.
        
    $backupas $database '.sql.' date "Ymd" ) . '.gz';
    // Perform backup
    $backupcommand "mysqldump -u$username -p$password $database | gzip >$backupto/$backupas";
    passthru ("$backupcommand"$error);
    if(
    $error) {
       echo (
    "Problem: $error\n"); exit;
    }
     
    ?>
    of course i removed the 'db_login.php' with my own

  9. #9
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Shouldn't be the $backupcommand without quotes ?
    Code:
    passthru ($backupcommand, $error);
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.

  10. #10
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by frezno
    Shouldn't be the $backupcommand without quotes ?
    Code:
    passthru ($backupcommand, $error);
    It shouldn't matter since I've used it like that for quite some time now.

    Ahmed, the script you pasted looks good and I can't really find any problems with it, other than maybe your server does not have support for gzip files. In that case use this:
    PHP Code:
    // Mysql Database Information:
        
    $database 'mofadla_favorite';   // name of the database.
        
    $username "mofadla_ahmed";  // username with access to database.
        
    $password "ahmed";  // password for username.
    // Database Backup Filename & Location
        
    $backupto '/home/mofadla/public_html/test/db';  // absolute path to folder containing database - no trailing slash.
        
    $backupas $database date "Ymd" ) . '.sql';
    // Perform backup
    $backupcommand "mysqldump -u$username -p$password $database > $backupto/$backupas";
    passthru ("$backupcommand"$error);
    if(
    $error) {
       echo (
    "Problem: $error\n"); exit;

    Community Guidelines | Community FAQ

    "He that is kind is free, though he is a slave;
    he that is evil is a slave, though he be a king." - St. Augustine

  11. #11
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    Norway
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem might be you have a space between -p and your password. Try removing the space so it says: -pahmed

  12. #12
    SitePoint Addict AHMED's Avatar
    Join Date
    Oct 2002
    Location
    Egypt
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's p$password ..

    there is no spaces ..

  13. #13
    SitePoint Addict AHMED's Avatar
    Join Date
    Oct 2002
    Location
    Egypt
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi toly .. it still gives Problem: 127 .. could u tell me plz what does these numbers mean .. this may help to fix it ..

    and thx alot 4 help

  14. #14
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, but I have never seen that error before, so I really don't know what it means. The only error I know about is "Problem: 1" which is related to folder permissions, but I just thought yours might have been related to the same problem.
    Community Guidelines | Community FAQ

    "He that is kind is free, though he is a slave;
    he that is evil is a slave, though he be a king." - St. Augustine

  15. #15
    SitePoint Addict Avido's Avatar
    Join Date
    Jul 2003
    Location
    Kortrijk, Belgium, Europe, the world
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't you have to specify a relative(or absolute path) for the 'mysqldump'-command?
    Something like: exec('blabla/bin/mysqldump -h localhost -u mofadla_ahmed -p ahmed favorite > db.sql') or die(mysql_error());

  16. #16
    Fully Sweet Car noddy's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Western Australia
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wrote a script at work for this exact thing the other day.

    You need to put the physical path to mysql and mysqldump in front of the command mysqldump so it would be something like /usr/sbin/mysqldump [AND THE REST OF THE COMMAND HERE\

  17. #17
    SitePoint Enthusiast sinatosk's Avatar
    Join Date
    Jul 2003
    Location
    PHP World
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this

    PHP Code:
    $backupcommand "mysqldump -u{$username} -p{$password} {$database} > {$backupto}/{$backupas}"
    or this

    PHP Code:
    $backupcommand 'mysqldump -u'.$username.' -p'.$password.' '.$database.' > '.$backupto.'/'.$backupas
    I did this earlier today in Linux

    /usr/bin/mysqldump -u root -pxxxxxxxx database > /path/to/dump/sql.sql

    and that worked fine ( I have installed MySQL on Linux using RPM packages )


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •