Post Reply  Post Thread 
Shell script to Backup all MySQL databases to files of their own
Author Message
admin
~CM~
*******


Posts: 147
Group: Administrators
Joined: Jul 2007
Status: Offline
Reputation: 0
Thank 0
2 was given thank in 2 posts
Post: #1
Shell script to Backup all MySQL databases to files of their own

If you want to backup all MySQL database a user has access to and dump them each to their own file, check out this quick script.

Filename : mysql_backup.sh

Quote:
#!/bin/bash
username="root_user"
password="your_mysql_pass"
mkdir mysql
for i in `echo "show databases" | mysql -u$username -p$password|grep -v Database`; do
#echo $i
mysqldump -u$username -p$password $i > $i.sql
done


This bash script simply creates a dump of each database, saved into the directory it is running from. i.e there are 3 databases: shoppingcart, blog_site, forums. When you run ’sh mysql_backup.sh’, these databases would be saved (as SQL dumps) in the directory the script was run as: shoppingcart.sql, blog_site.sql, forums.sql.

I hope this very simple & sweet script Tongue


Thanks & Regards
------------------
~CM~

ADD TO DEL.ICIO.US  ADD TO DIGG  ADD TO FURL  ADD TO NEWSVINE  ADD TO NETSCAPE 
ADD TO TECHNORATI FAVORITES  Technorati ADD TO SQUIDOO  ADD TO WINDOWS LIVE  ADD TO YAHOO MYWEB  ADD TO ASK 
ADD TO REDDIT  ADD TO STUMBLEUPON  ADD TO GOOGLE   

This post was last modified: 07-21-2007 10:04 PM by admin.

07-21-2007 10:02 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Rename all files in directory at once admin 0 443 07-25-2007 03:50 AM
Last Post: admin
  Usefull shell commands for System Information admin 0 144 07-21-2007 10:23 PM
Last Post: admin
  Server migration script Nilesh 0 630 07-16-2007 07:48 PM
Last Post: Nilesh

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: