Register
It is currently Fri Apr 18, 2014 12:12 am

Script to backup files


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Fri Jul 03, 2009 4:41 pm   

Joined: Wed Apr 08, 2009 12:41 pm
Posts: 15
I have a list of users with mysql databases (DB) and I need to backup their DBs. The DB names are saved in a simple text file, dbs.txt. Can I use this script?:

Code:
#!/bin/bash
for ext in $(cat dbs.txt)
  do
/usr/bin/mysqldump --opt -uUSERNAME -pPASSWORD --database "*.$ext" > ext.sql
  done


Any help is greatly appreciated.


Top
 Profile  
 PostPosted: Sat Jul 04, 2009 4:28 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
The dbs.txt file must contain the database names with only 1 entry on each row.
sajko@hanna:~> cat dbs.txt
database1
database2
database3

Then it would work.
For-loop reads each itteration based on whitespace seperation, so things that would be named "database 1" would become 2 itterations.

Also I believe that mysqldump is also useable like this.
Code:
for i in $(cat dbs.txt); do
   /usr/bin/mysqldump -uUSERNAME -pPASSWORD $ext > $ext.sql
done


Best regards
Fredrik Eriksson


Top
 Profile  
 PostPosted: Mon Jul 06, 2009 7:53 am   

Joined: Wed Apr 08, 2009 12:41 pm
Posts: 15
Thank you, Fredrik, for your time and help. All the best :)


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP