Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 21st April 2006, 02:42
sjau sjau is offline
Pseudo Lawyer
 
Join Date: Apr 2006
Location: Switzerland
Posts: 857
Thanks: 3
Thanked 25 Times in 23 Posts
Default 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
Reply With Quote
  #2  
Old 21st April 2006, 12:38
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 31,853
Thanks: 781
Thanked 1,558 Times in 1,477 Posts
Default

You can build one yourself with this information: http://www.howtoforge.com/faq/6_3_en.html
__________________
Falko
--
Follow me on:
Reply With Quote
  #3  
Old 11th June 2006, 10:44
EvanCarroll EvanCarroll is offline
Junior Member
 
Join Date: Jun 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #4  
Old 2nd September 2006, 23:00
thelorax thelorax is offline
Junior Member
 
Join Date: Jul 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.
Reply With Quote
  #5  
Old 3rd September 2006, 11:06
sjau sjau is offline
Pseudo Lawyer
 
Join Date: Apr 2006
Location: Switzerland
Posts: 857
Thanks: 3
Thanked 25 Times in 23 Posts
Default

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;
Reply With Quote
  #6  
Old 3rd September 2006, 20:31
drks drks is offline
Junior Member
 
Join Date: Aug 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
__________________
drks - http://www.5dollarwhitebox.org
Reply With Quote
  #7  
Old 3rd December 2008, 06:47
Tenaka Tenaka is offline
Senior Member
 
Join Date: Sep 2005
Posts: 840
Thanks: 15
Thanked 2 Times in 2 Posts
Default

what would we need to change to make any of these scripts compress the dumps into .gz or similar?
Reply With Quote
  #8  
Old 3rd December 2008, 09:44
sjau sjau is offline
Pseudo Lawyer
 
Join Date: Apr 2006
Location: Switzerland
Posts: 857
Thanks: 3
Thanked 25 Times in 23 Posts
Default

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.
__________________
Need more Repos for Ubuntu? Repository Generator

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!
Reply With Quote
  #9  
Old 5th December 2008, 01:22
Tenaka Tenaka is offline
Senior Member
 
Join Date: Sep 2005
Posts: 840
Thanks: 15
Thanked 2 Times in 2 Posts
Default

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.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Backup of Client Webspaces and Databases JohnSmith Feature Requests 5 2nd July 2007 09:53
Spam Databases plucchetti Installation/Configuration 4 7th March 2006 00:09
website's databases names Prompt General 2 19th October 2005 10:54
Rename Databases AngelDrago Installation/Configuration 2 18th October 2005 07:01


All times are GMT +2. The time now is 02:46.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Sponsored Links: Unified Communications: Thoughts, Strategies and Predictions
Join the discussion.
www.seamlessenterprise.com

IP Convergence
Integrate your wireless and wireline networks.
Learn how from the experts at Sprint.
www.seamlessenterprise.com

Wireless & Wireline Integration
Thoughts, strategies and solutions: join the discussion
www.seamlessenterprise.com

Unified Communications 2009
Join the Discussion. Now.
www.seamlessenterprise.com

Red Hat Virtual Experience - a free virtual event. Dec. 9th