Hello folks,<br /><br />didn't see anything to do this so I wrote a small script that automatically dumps the database to a file.<br /><br />you just need to download attachment, rename to PHP, edit and replace path to mysqldump, backup folder and format of filename. <br /><br />Then simply copy to your admin folder and call it from there.<br /><br />don't forget to create the backup dir <img src="/forum/images/icons/wink.gif" alt="" /> for added security I made mine above webroot.<br /><br />this file can also be called by cron.<br /><br />Feedback is welcome<br /><br />Cheers<br /><br />Charles
well already working on the restore part <img src="/forum/images/icons/smile.gif" alt="" /><br /><br />I might also add a backup of the main threads directory since some files in it are important
_________________________
Do you believe in love at first sight, or should I walk by again?
OK just did a new version that enables putting a backup back<br /><br />tried to keep it simple, for the moment backup has to be on server will try to see how to upload it first.<br /><br />If a PHP guru could check my code to see if I didn't mess anything, that would be great <img src="/forum/images/icons/wink.gif" alt="" /><br /><br />Charles
#216598 - 05/10/0208:21 PMRe: Auto MYSQL Backup
[Re: egor]
Ian_W
Veteran
Registered: 02/22/02
Posts: 2575
Loc: England
Nice one.<br /><br />This would be one feature that would be a excellent addition to the core package, as loosing the database has some fairly major consequences to the running of threads...<br /><br />Thanks again.
_________________________ Fans Focus - Focusing on Fans of Sport
(Okay - mainly football (the British variety at the moment - but expanding all the time....)
Registered: 04/23/02
Posts: 1929
Loc: Virginia, USA
The script looks useful. <img src="/forum/images/icons/smile.gif" alt="" /><br /><br />I spent some time reading the MySQL manual to figure out how to do backups, and came up with a few issues which may affect your script. If you're a MySQL guru, perhaps you could look at my post and give me your opinion. <img src="/forum/images/icons/wink.gif" alt="" />
_________________________
UBB.threads beta tester / threadsdev.com moderator Software consulting services including UBB.threads problem resolution / installs / upgrades / customization.
your idea is good, but there is a real problem I think. You are gonna dump the WHOLE database at one time. This could crash if<br />a) the isp has memory restrictions for scripts<br />b) the isp has time restrictions for script<br /><br />My table w3t_Posts has 30MB and every time I wanna backup with such a funktion the script dies with an error like "Mysqldump rans out of memory"<br /><br />So I wrote a recursivly script to do the work and one which do the work for at least one table.<br /><br />I´ve to make some changes to it and the I share the scripts this weekend.<br />
OK cola I added a function to the script:<br /><br />it will first store all tables in an array and then will dump them one by one.<br /><br />tell my how its works for you
OK updated version (again)<br /><br />added the -opt tag for better dump<br /><br />restore now uses all files in a specified dir to copy into database.<br /><br />Feedback is welcome since I am not sure my loops are very well coded <img src="/forum/images/icons/tongue.gif" alt="" /><br />
Registered: 04/23/02
Posts: 1929
Loc: Virginia, USA
1) Shouldn't "-opt" be "--opt"?<br /><br />2) You could optimize the loops slightly by removing processing that doesn't need to be done on every loop iteration, but I doubt if it really matters here, since there are only 17 tables.<br /><pre><font class="small">code:</font><hr><br />$COMMAND_DO = $PATHTOMYSQLDUMP . "mysqldump -opt -h" . $config['dbserver']<br /> . " -u" . $config['dbuser'] . " -p" . $config['dbpass']<br /> . " " . $config['dbname'] . " ";<br /><br />for ($i=0; $i<count($tb_names); $i++) {<br /> $table_name = $tb_names[$i];<br /> echo "$table_name<br />";<br /> $COMMAND_DO .= "$table_name > $DIRNAME.$table_name.sql";<br /></pre><hr>
_________________________
UBB.threads beta tester / threadsdev.com moderator Software consulting services including UBB.threads problem resolution / installs / upgrades / customization.
#216607 - 05/12/0212:00 AMRe: Auto MYSQL Backup
[Re: joeuser]
AllenAyres
I type Like navaho
Registered: 03/10/00
Posts: 25452
Loc: Texas
Nice work guys, this would work on v6 as well, eh? If I remember right, v6 added a table over previous versions tho <img src="/forum/images/icons/smile.gif" alt="" />
Dave, I tried to use your code but the script went berserk, something must be wrong.<br /><br />Allen, this will work on any version but I am still unsure of the limitations that could be caused by a big table.
_________________________
Do you believe in love at first sight, or should I walk by again?
mario2
Enthusiast
Registered: 07/08/99
Posts: 470
Loc: Los Angeles, Rio de Janeiro, M...
here is mine. runs through a cron job.<br /><br />It creates SEVERAL backups, because often there is a corruption and it already is in 1-2 backups before I discover it. I back up every 12 hours<br /><br />[root@a3p mario]# crontab -l<br /># DO NOT EDIT THIS FILE - edit the master and reinstall.<br /># (/tmp/crontab.7136 installed on Sun Jul 7 09:50:34 2002)<br /># (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)<br />28 */12 * * * /root/cron/cron_mysqlbackup<br /><br />[root@a3p mario]# <br /><br /><br />If you have passwords, of course, add the passwords<br />Note the NICE!!<br /><br />Question:<br />what happens to writes during backup? mysql can back up for half an hour during writes? If it blocks the database, I might as well remove the nice..<br /><br /><br />[root@a3p mario]# cat /root/cron/cron_mysqlbackup<br />mv /opt2/backups_mysql/ac2backup.gz.13 /opt2/backups_mysql/ac2backup.gz.14<br />mv /opt2/backups_mysql/ac2backup.gz.12 /opt2/backups_mysql/ac2backup.gz.13<br />mv /opt2/backups_mysql/ac2backup.gz.11 /opt2/backups_mysql/ac2backup.gz.12<br />mv /opt2/backups_mysql/ac2backup.gz.10 /opt2/backups_mysql/ac2backup.gz.11<br />mv /opt2/backups_mysql/ac2backup.gz.9 /opt2/backups_mysql/ac2backup.gz.10<br />mv /opt2/backups_mysql/ac2backup.gz.8 /opt2/backups_mysql/ac2backup.gz.9<br />mv /opt2/backups_mysql/ac2backup.gz.7 /opt2/backups_mysql/ac2backup.gz.8<br />mv /opt2/backups_mysql/ac2backup.gz.6 /opt2/backups_mysql/ac2backup.gz.7<br />mv /opt2/backups_mysql/ac2backup.gz.5 /opt2/backups_mysql/ac2backup.gz.6<br />mv /opt2/backups_mysql/ac2backup.gz.4 /opt2/backups_mysql/ac2backup.gz.5<br />mv /opt2/backups_mysql/ac2backup.gz.3 /opt2/backups_mysql/ac2backup.gz.4<br />mv /opt2/backups_mysql/ac2backup.gz.2 /opt2/backups_mysql/ac2backup.gz.3<br />mv /opt2/backups_mysql/ac2backup.gz.1 /opt2/backups_mysql/ac2backup.gz.2<br />mv /opt2/backups_mysql/ac2backup.gz /opt2/backups_mysql/ac2backup.gz.1<br /><br /><br />/bin/nice /usr/bin/mysqldump db4 >/opt2/backups_mysql/ac2backup<br /><br /> <br />/bin/nice /bin/gzip /opt2/backups_mysql/ac2backup<br /><br /><br />