matd Posted April 30, 2003 Share Posted April 30, 2003 Hi, I\'ve written a backup script which saves the output from a mysqldump and then prompts the uers to save the file. I have this working perfectly on my test server which is running apache on windows xp. But on the live server which is linux based the contents of the saved mysqldump are different. I get these characters in the file :- The mysqldump i run here is fine and formatted correctly when i look at it in notepad and i can import it into mysql using phpmyadmin with no problems. But when i look at the version i download from the live server it has in it and the formatting is all over the place and i get errors if i try and import it in phpmyadmin. I\'m sure i have set the correct mime-type and the headers are correct too. Any ideas why? Any help would be grealty appreciated Quote Link to comment Share on other sites More sharing options...
barbatruc Posted April 30, 2003 Share Posted April 30, 2003 I had the same problem and discovered that it was a problem with carriage returns ® against newline (n). I don\'t remember how I did the fix but this may help you if you can tell us if the special characters are replacing the newline characters. JP. Quote Link to comment Share on other sites More sharing options...
matd Posted April 30, 2003 Author Share Posted April 30, 2003 Whoa! that was quick! :-) Well, heres a sample of the dump :- `nALTER TABLE admin DISABLE KEYS */; -- -- Dumping data for table \'admin\'; -- -- thats the first line of the code, it does seem to be a carriage return problem as when i pasted that line above it appeared as:- `nALTER TABLE admin DISABLE KEYS */; -- -- Dumping data for table \'admin\' -- Wonder why it would be different or changes characters when the same script running locally here works perfectly. Would it be a case of converting some characters after the dump has run then? Quote Link to comment Share on other sites More sharing options...
effigy Posted April 30, 2003 Share Posted April 30, 2003 what are you viewing the file in? some viewers do not support both windows and unix line endings. www.textpad.com is very basic, free, and can read and write either format. Quote Link to comment Share on other sites More sharing options...
matd Posted April 30, 2003 Author Share Posted April 30, 2003 i was just using Notepad which i thought would show the bare file and ignore any formatting chars. I\'ll try and look at it in textpad... Still leaves the problem that i can backup and restore a mysql database in windows but can\'t backup a mysql database in Linux and restore it on a Windows platform. Will i need to convert the line endings or somthing? Quote Link to comment Share on other sites More sharing options...
effigy Posted May 1, 2003 Share Posted May 1, 2003 when saving a file, textpad allows you to choose whether the line endings should be windows or unix. code-wise... there is a unix script to do this but it has escaped me at the moment... you should also be able to parse it in php. Quote Link to comment Share on other sites More sharing options...
matd Posted May 1, 2003 Author Share Posted May 1, 2003 mysqldump --opt -c -hlocalhost -u$user -p$password $database | unix2dos | gzip > \" . $backup_dir . \'/\' . $backup_file By piping to unix2dos before gzip it converts all unix chars to dos / windows ones :-) Quote Link to comment Share on other sites More sharing options...
effigy Posted May 1, 2003 Share Posted May 1, 2003 that\'s it! Quote Link to comment Share on other sites More sharing options...
matd Posted May 1, 2003 Author Share Posted May 1, 2003 You wouldnt happen to know how i can terminate output to the header i\'ve set that allows me to save the dump to file would you? I have an index.php which has a button for backup. When backup is clicked it forwards the browser to backup.php where i set the header information for file saving and then echo the file. The only thing is, after the file has been saved i\'d like to put a link on that page to direct them back to another page, but as the header has been set it just gets put in with the file being saved. Is there someway of doing :- header(\'Content-Disposition: attachment; filename=\"\'. $saveas_filename . \'\"\'); header(\'Cache-Control: must-revalidate, post-check=0, pre-check=0\'); header(\'Pragma: public\'); echo $dump_buffer; <terminate output to file> <continue with php and html for page content displayed to browser> Help as always, is very much appreciated Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.