Automating Mysql Db Backup

windows

Guest
Whats the best way to automate a mySQL DB BACKUP? I tried using a crontab with this <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->mysqldump -udbusername -pdbpassword dbname > mybackup.sql<!--c2--></div><!--ec2--> but when i try to restore via phpmyadmin I get this error <br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->MySQL said: <br /><br /><br />You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '--------------------------------------------------------- <br />--<!--c2--></div><!--ec2--><br /><br />I'm almost sure whats causing the error. Its some of the lines that start in -------, instead they need to have ###. Is there a way I can have the mysqldump use #'s instead of -'s.<!--content-->
One last bump.<br /><br /> TCH Stones<!--content-->
Give this one a try.<br /><br /><a href="http://www.phpfreaks.com/script/view/11.php" target="_blank">http://www.phpfreaks.com/script/view/11.php</a><!--content-->
UH, thanks for the nice script, but this still doesn't solve my problem with the - not being friendly to phpmyadmin. The mysqldump from the commandline seems to always use - instead of #. In the meantime, I've been using a search and replace which works fine but its more work for me. Its not like i'm going to be restoring my db anytime soon, its just in case. ya know<br /><br />I decided to try this script for s***s and giggles anyway. But for some reason my db is being corrupt during the ftp transfer to my computer. The gzip file is perfect on the server itself, but during the ftp transfer it gets corrupted. Any idea whats causing this. <br /><br />Must be something to do with this syntax. <br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->$ftpconnect = "ncftpput -u $ftp_user_name -p $ftp_user_pass -d debsender_ftplog.log -e dbsender_ftplog2.log -a -E -V $ftp_server $ftp_path $filename2";<br /><br />shell_exec($ftpconnect);<!--c2--></div><!--ec2--><br /><br />Any Ideas?<!--content-->
Well, if you actually made it to the part where you have a gzip file with an actual database backup in it, you've gone farther than I did. The script says everything is ok but the file is actually empty.<br />So I tried executing the mysqldump command directly and got this:<br /><br />mysqldump: Got error: 1044: Access denied for user: 'best-alm@localhost' to database 'bestalm_ipb' when using LOCK TABLES<br /><br />It's not the same problem you have but I don't know how to fix any of them <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/sad.gif" style="vertical-align:middle" emoid=":(" border="0" alt="sad.gif" /><!--content-->
OK, after taking a look at the mysqldump man page, I found that the --opt argument that the script uses is what's causing the LOCK TABLES error (it implicitly adds the --lock-tables option to the command line).<br /><br />So I opened up the script and changed this line (67):<br /><br />passthru("mysqldump --opt -h$dbhost -u$dbuser -p$dbpass $dbname >$filename");<br /><br />into this:<br /><br />passthru("mysqldump -a -e -h$dbhost -u$dbuser -p$dbpass $dbname >$filename");<br /><br />and now it works like a charm.<br />I now have a cron job with the following command:<br /><br />php -q /path/to/script/dbsender.php<br /><br />and it works just fine.<br />I received the file in my e-mail and it looks OK but I didn't try it with the FTP option, though.<br /><br /><br />But anyway, now I understand your problem with the '---'<br />I wasn't understanding your problem before but once I opened the .sql file, I realized that I wouldn't be able to import that data with phpMyAdmin.<br /><br />mysqldump's man page says we can read the backup back into mysql with one of the following commands:<br /><br />mysql database < backup-file.sql<br />or<br />mysql -e 鎶痮urce /patch-to-backup/backup-file.sql?database<br /><br />I tried both commands and none of them worked. The second even has something wrong in its syntax, since MySQL output the whole 'how-to-use' stuff.<br />So right now I'm trying to get a way to either have mysqldump output ## instead of -- or a way to import the file with -- into MySQL.<br />If I find something, I'll post it here.<!--content-->
Straight from the phpMyAdmin FAQ:<br /><br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->[3.4]I am unable to import dumps I created with the mysqldump tool bundled with the MySQL server distribution.<br /><br />The problem is that mysqldump creates invalid comments like this:<br /><br />-- MySQL dump 8.22<br />--<br />-- Host: localhost Database: database<br />---------------------------------------------------------<br />-- Server version 3.23.54<br /><br />The invalid part of the code is the horizontal line made of dashes that appears once in every dump created with mysqldump. If you want to run your dump you have to turn it into valid MySQL. This means, you have to add a whitespace after the first to dashes of the line or add a # before it:<br />-- -------------------------------------------------------<br />or<br />#---------------------------------------------------------<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />So now we just have to find a way correct all the lines with more than two followed dashes.<br />This shouldn't be hard and since I don't suppose we'll need to import backups everyday, it should't be a bother <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><!--content-->
Yup, like i said. Shouldn't be a serious problem, I'll just do it manually. And yes, i hate to make a few modifications to the script for it to work, but overall a descent script.<!--content-->
 
Top