
21st April 2006, 02:42
|
|
Pseudo Lawyer
|
|
Join Date: Apr 2006
Location: Switzerland
Posts: 857
Thanks: 3
Thanked 25 Times in 23 Posts
|
|
replacement for mysqldump --all-databases
Hiya
anyone knows a script that loops through all existing mysql dbs and makes a dump of them. So that you end up with multiple sql files e.g.
dump_db1.sql
dump_db2.sql
dump_db3.sql
|

21st April 2006, 12:38
|
|
Super Moderator
|
|
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 31,853
Thanks: 781
Thanked 1,558 Times in 1,477 Posts
|
|
You can build one yourself with this information: http://www.howtoforge.com/faq/6_3_en.html
|

11th June 2006, 10:44
|
|
Junior Member
|
|
Join Date: Jun 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The rightmost way to accomplish this -- how i would do it, is to querry on the information_schema http://dev.mysql.com/doc/refman/5.0/...ata-table.html CATALOG_NAME is database. that will get you a list of dbs, you can then easily dump in parellel to a like named file. using the command above.
Quote:
|
Originally Posted by sjau
Hiya
anyone knows a script that loops through all existing mysql dbs and makes a dump of them. So that you end up with multiple sql files e.g.
dump_db1.sql
dump_db2.sql
dump_db3.sql
|
|

2nd September 2006, 23:00
|
|
Junior Member
|
|
Join Date: Jul 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Try automysqlbackup
Give AutoMySQL backup a try - http://sourceforge.net/projects/automysqlbackup/
You can set it up to do specific databases or all of them and it will also do a daily/weekly/monthly rotation for you.
|

3rd September 2006, 11:06
|
|
Pseudo Lawyer
|
|
Join Date: Apr 2006
Location: Switzerland
Posts: 857
Thanks: 3
Thanked 25 Times in 23 Posts
|
|
if you want to have a unique sql for each database:
Code:
#!/bin/bash
unset PATH
# USER VARIABLES
MYSQLUSER=root
MYSQLPWD=**********************
MYSQLHOST=localhost
MYSQLBACKUPDIR=/mysql_backup
# PATH VARIABLES
MK=/bin/mkdir;
RM=/bin/rm;
GREP=/bin/grep;
MYSQL=/usr/bin/mysql;
MYSQLDUMP=/usr/bin/mysqldump;
# CREATE MYSQL BACKUP
# Remove existing backup dir
$RM -Rf $MYSQLBACKUPDIR
# Create new backup dir
$MK $MYSQLBACKUPDIR
#Dump new files
for i in $(echo 'SHOW DATABASES;' | $MYSQL -u$MYSQLUSER -p$MYSQLPWD -h$MYSQLHOST|$GREP -v '^Database$'); do
$MYSQLDUMP \
-u$MYSQLUSER -p$MYSQLPWD -h$MYSQLHOST \
-Q -c -C --add-drop-table --add-locks --quick --lock-tables \
$i > $MYSQLBACKUPDIR/$i.sql;
done;
|

3rd September 2006, 20:31
|
|
Junior Member
|
|
Join Date: Aug 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I do this with a one liner (for onetime backups).... you could break it up into a script if you wanted (or use the great suggestions above):
Code:
linuxbox /]# for database in $(mysql -e "show databases" | grep "^\|" | grep -v Database); \
do echo -n "backing up $database ... "; \
mysqldump $database > $database.sql && \
echo "ok" || \
echo "failed"; \
done
|

3rd December 2008, 06:47
|
|
Senior Member
|
|
Join Date: Sep 2005
Posts: 840
Thanks: 15
Thanked 2 Times in 2 Posts
|
|
what would we need to change to make any of these scripts compress the dumps into .gz or similar?
|

3rd December 2008, 09:44
|
|
Pseudo Lawyer
|
|
Join Date: Apr 2006
Location: Switzerland
Posts: 857
Thanks: 3
Thanked 25 Times in 23 Posts
|
|
you just need to add at the end of my script the command to create tgz or whatever you want... with my script you have all the files in one folder so just zip that one.
__________________
In a world without walls and fences, who needs Windows and Gates?
Linux is like a wigwam.... no Gates, no Windows and Apache inside!
There are 10 different kind of people... those who understand binary and those who don't!
|

5th December 2008, 01:22
|
|
Senior Member
|
|
Join Date: Sep 2005
Posts: 840
Thanks: 15
Thanked 2 Times in 2 Posts
|
|
would that look something like this?
Quote:
for i in $(echo 'SHOW DATABASES;' | mysql -u$USER -p$PASSWORD -h$HOST|grep -v '^Database$'); do
mysqldump \
-u$USER -p$PASSWORD -h$HOST \
-Q -c -C --add-drop-table --add-locks --quick --lock-tables \
$i > /root/mysql_backup/$i.sql;
tar czvf $i.sql.tar.gz /root/mysql_backup/$i.sql;
done;
|
I'd like to tar.gz the single DB dumps, not the whole folder.
I am terribly bad with this stuff :-(
###edit###
above code gives an error about removing a / so I changed to this:
Quote:
|
tar czvf /root/mysql_backup/$i.sql.tar.gz -C / root/mysql_backup/$i.sql;
|
Last edited by Tenaka; 5th December 2008 at 02:04.
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT +2. The time now is 02:46.
|
Recent comments
18 hours 13 min ago
23 hours 29 min ago
23 hours 40 min ago
23 hours 48 min ago
1 day 50 min ago
1 day 2 hours ago
1 day 5 hours ago
1 day 5 hours ago
1 day 5 hours ago
1 day 7 hours ago