Welcome to WebmasterWorld Guest from 54.159.214.250

Forum Moderators: coopster & jatar k

Backup mysql file empty

mysql backup

   
2:38 pm on Jul 16, 2010 (gmt 0)

5+ Year Member



hi,

i tried to backup one of my table, the sql file backup & created but empty content. What would be the problem here anyway?


<?php

$tabel = $_POST['tabel'];

$listTabel = "";
foreach($tabel as $namatabel)
{
$listTabel .= $namatabel." ";
}

$command = "mysqldump -u".$dbUser." -p".$dbPass." ".$dbName." ".$listTabel." > ".$dbName.".sql";

exec($command);

header("Content-Disposition: attachment; filename=".$dbName.".sql");
header("Content-type: application/download");
$fp = fopen($dbName.".sql", 'r');
$content = fread($fp, filesize($dbName.".sql"));
fclose($fp);

echo $content;
exit;
?>

4:43 pm on Jul 16, 2010 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



When you do this

>

you are executing a system command to dump into "file" and it will dump whatever is output from mysql dump. mysqldump is returning nothing.

These can be a bear to debug. It varies from system to system, anything from an authentication error to a missing switch to the switches not being in the right order to . . . who knows. :-)

I'm guessing, a couple things, no space or = setting the variable, no hostname or --h switch, but it could be other things. Even if this works,

-u".$dbUser." -p".$dbPass."

you have

-uusername -ppassword

when you need

-u username -p password

Try this one, it works for me, sub out your values. I have defined them as constants (the parts IN_CAPITALS) in this program, use variables if you like. As you see, I left a comment in for one that hung me up for a couple hours. :-)

$result=null;
$file = DB . '-' . $current_date . '.sql'; // DB = database name
// So you get "your-database-2010-07-16.sql"
// DB_BU_DIR = '/path/to/backup/directory/' make sure it's writable

# connecting remote requires hostname --h
$cmd = 'mysqldump -h ' . DBHOST . ' --user=' . DBUSER . ' --password=' . DBPASSWORD . ' ' . DB . ' > ' . DB_BU_DIR . "$file";

$result = system($cmd);

if ($result) { die("Error, something went goofy: $result"); }
else { echo "Success"; }

$result should be null or 0, but it's no guarantee it won't give you an empty file if something is . . . goofy. It will most often have a numeric value, and you'll need to look up the documentation for your O.S. to find out what the number means. Like I said, can be a bear . . .
 

Featured Threads

Hot Threads This Week

Hot Threads This Month