Jump to content

tar corrupts my sql file


castor_troy

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.