castor_troy Posted July 12, 2008 Share Posted July 12, 2008 I backed up my database using this code: exec("mysqldump --opt --host=$db_host --user=$db_user --password=$db_pass '$db_name' > $filename.sql"); exec("tar czvf $filename.tar.gz $filename.sql"); now I'm trying to restore my database by uploading the file and then run this code exec("tar -zxvf $filename", $file); exec("mysql --verbose --user=$db_user --password=$db_pass $db_name < ".$db_name."-db-globackup.sql", $result, $response); now my sql file is extracted successfully but the content has lots of special characters, words misspelled etc. what could be the problem with my script? TIA Link to comment https://forums.phpfreaks.com/topic/114364-tar-corrupts-my-sql-file/ Share on other sites More sharing options...
DarkWater Posted July 12, 2008 Share Posted July 12, 2008 You verified that the SQL file is created properly by mysqldump, correct? Link to comment https://forums.phpfreaks.com/topic/114364-tar-corrupts-my-sql-file/#findComment-588102 Share on other sites More sharing options...
castor_troy Posted July 12, 2008 Author Share Posted July 12, 2008 yup. it actually runs properly when extracted in windows and I do the mysql restore in command prompt. it also runs properly in php if not for the corrupted sql file. Link to comment https://forums.phpfreaks.com/topic/114364-tar-corrupts-my-sql-file/#findComment-588104 Share on other sites More sharing options...
mbeals Posted July 12, 2008 Share Posted July 12, 2008 If I remember correctly, mysql cannot be running during a dump. Try stopping the service before dumping and see if that fixes it. I actually run master slave replication on my master sql server and have a bash script that shuts down the slave, dumps it, restarts mysql then tars the dumped file. It requires a second machine, but it means zero downtime to backup the db and I have a live realtime mirror of the db in case the entire server drops. Link to comment https://forums.phpfreaks.com/topic/114364-tar-corrupts-my-sql-file/#findComment-588125 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.