php forum
php mysql forum
php mysql smarty
 
Topic Options
#216594 - 05/10/02 05:25 PM Auto MYSQL Backup
Charles Offline
Veteran

Registered: 10/22/00
Posts: 2637
Loc: London, UK
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


Attachments
47606-backup.txt (116 downloads)

_________________________
Do you believe in love at first sight,
or should I walk by again?

Top
#216595 - 05/10/02 06:37 PM Re: Auto MYSQL Backup [Re: egor]
JustDave Offline
That 70's Guy

Registered: 06/24/01
Posts: 4097
Thanks! been wanting to replace my cgi script. <img src="/forum/images/icons/smile.gif" alt="" />
_________________________
~Dave
ChattersOnline.com

Top
#216596 - 05/10/02 06:41 PM Re: Auto MYSQL Backup [Re: sjsaunders]
Charles Offline
Veteran

Registered: 10/22/00
Posts: 2637
Loc: London, UK
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?

Top
#216597 - 05/10/02 07:41 PM Re: Auto MYSQL Backup [Re: egor]
Charles Offline
Veteran

Registered: 10/22/00
Posts: 2637
Loc: London, UK
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


Attachments
47613-backup.txt (302 downloads)

_________________________
Do you believe in love at first sight,
or should I walk by again?

Top
#216598 - 05/10/02 08:21 PM Re: Auto MYSQL Backup [Re: egor]
Ian_W Offline

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 wink at the moment - but expanding all the time....)

Top
#216599 - 05/10/02 09:21 PM Re: Auto MYSQL Backup [Re: egor]
Dave_L_dup1 Offline
Addict

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.

Top
#216600 - 05/11/02 01:08 AM Re: Auto MYSQL Backup [Re: egor]
Cola Offline
Newbie

Registered: 03/25/02
Posts: 14
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 />

Top
#216601 - 05/11/02 03:42 AM Re: Auto MYSQL Backup [Re: bjarnerasmussen]
Charles Offline
Veteran

Registered: 10/22/00
Posts: 2637
Loc: London, UK
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


Attachments
47627-backup.txt (295 downloads)

_________________________
Do you believe in love at first sight,
or should I walk by again?

Top
#216602 - 05/11/02 04:10 AM Re: Auto MYSQL Backup [Re: joeuser]
Charles Offline
Veteran

Registered: 10/22/00
Posts: 2637
Loc: London, UK
Dave I replied to your post <img src="/forum/images/icons/wink.gif" alt="" />
_________________________
Do you believe in love at first sight,
or should I walk by again?

Top
#216603 - 05/11/02 04:34 AM Re: Auto MYSQL Backup [Re: egor]
Dave_L_dup1 Offline
Addict

Registered: 04/23/02
Posts: 1929
Loc: Virginia, USA
I saw the reply. Thanks for answering my questions. <img src="/forum/images/icons/smile.gif" alt="" />
_________________________
UBB.threads beta tester / threadsdev.com moderator
Software consulting services including UBB.threads problem resolution / installs / upgrades / customization.

Top
#216604 - 05/11/02 10:07 AM Re: Auto MYSQL Backup [Re: joeuser]
Charles Offline
Veteran

Registered: 10/22/00
Posts: 2637
Loc: London, UK
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 />


Attachments
47639-backup.txt (88 downloads)

_________________________
Do you believe in love at first sight,
or should I walk by again?

Top
#216605 - 05/11/02 12:53 PM Re: Auto MYSQL Backup [Re: egor]
Dave_L_dup1 Offline
Addict

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.

Top
#216606 - 05/11/02 01:08 PM Re: Auto MYSQL Backup [Re: joeuser]
Dave_L_dup1 Offline
Addict

Registered: 04/23/02
Posts: 1929
Loc: Virginia, USA
Also (since you asked for feedback on the loops <img src="/forum/images/icons/smile.gif" alt="" />), my preference would be to use foreach, since the index isn't needed inside the loop here:<br /><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 />foreach ($tb_names as $table_name) {<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.

Top
#216607 - 05/12/02 12:00 AM Re: Auto MYSQL Backup [Re: joeuser]
AllenAyres Offline

I type Like navaho

Registered: 03/10/00
Posts: 25580
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="" />
_________________________
- Allen wavey
- What Drives You?

Top
#216608 - 05/16/02 07:33 AM Re: Auto MYSQL Backup [Re: joeuser]
Charles Offline
Veteran

Registered: 10/22/00
Posts: 2637
Loc: London, UK
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?

Top
#216609 - 07/14/02 03:53 AM linux shell script backup [Re: egor]
mario2 Offline
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 />

Top



Latest Posts
[7.2.1] - Naked shoutbox
by bellaonline
05/05/12 05:00 PM
[7.x] Stop Forum Spam Integration v0.4
by bellaonline
05/05/12 03:53 PM
Shout Box

(Views)Popular Topics
Known public proxy servers 1689885
Integrated Index Page (IIP) 5.3.1 555705
Finished-[6.5.2] Games Arcade Deluxe v1.9 501236
Integrated Index Page (IIP) 5.1.1 415112
TLD Bv2.1 Released - Threads Links Directory 396822
[6.0x] Who's Online 4.0.0 [Finished] 389412
Finished-[6.5.1] Integrated Index Page (IIP) 6.5 330423
Q & A 298663
Slash UBB 266936
[6.3.x] [beta] Hit Hack 2.0 227970
Forum Stats
13621 Members
59 Forums
37191 Topics
295716 Posts

Max Online: 686 @ 06/28/07 07:04 AM

 

 

 
fusionbb message board php hacks