PDA

View Full Version : replacement for mysqldump --all-databases


sjau
21st April 2006, 02:42
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

falko
21st April 2006, 12:38
You can build one yourself with this information: http://www.howtoforge.com/faq/6_3_en.html :)

EvanCarroll
11th June 2006, 10:44
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/en/schemata-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.


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

thelorax
2nd September 2006, 23:00
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.

sjau
3rd September 2006, 11:06
if you want to have a unique sql for each database:


#!/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;

drks
3rd September 2006, 20:31
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):


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

Tenaka
3rd December 2008, 06:47
what would we need to change to make any of these scripts compress the dumps into .gz or similar?

sjau
3rd December 2008, 09:44
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.

Tenaka
5th December 2008, 01:22
would that look something like this?

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:
tar czvf /root/mysql_backup/$i.sql.tar.gz -C / root/mysql_backup/$i.sql;