Hi Community (to which I am new),
I'm going nuts. For hours now I am trying to find the right code for restoring a backupfile, that I got through mysqqldump. Here ist what I am trying to do:
I let users create a backupfile of their database through a web-interface:
With:
system(sprintf(
'mysqldump --opt --hex-blob --complete-insert --extended-insert --quick --create-options -h%s -u%s -p"%s" %s | gzip > %s',
$dbhost,
$dbuser,
$dbpass,
$dbname,
"path_and_filename.sql.gz");
I am successfully creating the files. If I manually download the files and import them via phpmyadmin to the beforehand emptied database, I get the wanted result, everthing works fine so far.
But I want to restore the data through a php-Program, so that the users can restore their data themselves.
I already tried:
system(sprintf('gunzip < %s | mysql -u%s -p%s -h%s %s',
"path_and_filename.sql.gz",
$dbuser,
$dbpass,
$dbhost,
$dbname
));
Didn't work: the return_value of the php-command system was '1'. Then I tried to unzip the file first and then import the uncompressed data into the database:
system('gunzip path_and_filename.sql.gz > path_and_filename.sql'); // which was successful
But neither
system(sprintf('mysql -u%s -p%s -h%s %s < %s',
$dbuser,
$dbpass,
$dbhost,
$dbname
));
nor
system(sprintf('mysqlimport -u%s -p%s -h%s %s %s',
$dbuser,
$dbpass,
$dbhost,
$dbname
));
seem to do the trick for me. Both result in '1' as return_value for the system-command.
Am I on the totally wrong path here? Any hints or tips or tricks on how to succeed or what the problem might be?
The system is running on a 1&1-Virtual-Server (actually just a Pro-Webspace with Shell-Access, etc...) The databases are stored on remote hosts. But as I mentioned backingup with mysqldump, downloading, importing via phpmyadmin works totally fine. Is it possible that I can't do fileimports through the shell because of restrictions by 1&1?
Thanks in advance
hbergman