Database Backup

Discussion in 'PHP' started by babaMBA, Aug 6, 2007.

  1. #1
    i want to take backup of my database with a single click of user.

    I am using mysqldump to do so, It creates .sql file but not contain any thing int it.

    Here is the code.

    $backupFile = $dbname . date("Y-m-d") . '.sql';
    $command = "mysqldump --opt -h $host -u $user -p $password $database > $backupFile";

    $backupCheck = system($command);

    if($backupCheck)
    {
    echo ("Success");
    }
    else
    {
    echo ("Fail bakcup");
    }
    Plz help me , wat wrong with this code and how can i solve my problem
     
    babaMBA, Aug 6, 2007 IP
  2. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Should you be specifying full path to mysqldump? Usually /usr/bin/mysqldump on *nix servers
    And just in case, you are setting the host, user, pass and database vars, right?
     
    krt, Aug 6, 2007 IP
  3. babaMBA

    babaMBA Guest

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Vars hots, user, password and datbase are 100% right, I m sure about that.

    The second thing is not clear ...... i want to take and test backup at localhost host using Apache webserver and mysql 4.19 version and then i want to shift that backup code to online.

    What can i do.
     
    babaMBA, Aug 6, 2007 IP
  4. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #4
    So you have this script setup on a local server, Windows?

    Try $command = 'c:\path\to\mysql\bin\mysqldump ...
     
    krt, Aug 6, 2007 IP
  5. babaMBA

    babaMBA Guest

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi,

    On localhost i tried this

    $command = "C:\Program Files\EasyPHP1-8\mysql\bin\mysqldump --opt -h $host -u $user -p $password $database > custback.sql";

    but it fails again. Again it creats custback.sql file but again with 0KB. Plz help me how can i solve it.
     
    babaMBA, Aug 6, 2007 IP
  6. ecentricNick

    ecentricNick Peon

    Messages:
    351
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #6
    If you have access to the console on your server - for example, through putty, run the command manually without the redirect (> custback.sql) so that you can see any error returned in the console.
     
    ecentricNick, Aug 7, 2007 IP