Jump to content

Recommended Posts

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.