[SOLVED] How to backup a particular Database!! in MYSQL
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
#!/bin/bash
date=`date +%Y-%m-%d_%H.%M.%S`
echo Backup Started $date >> /var/tmp/mysqlbackuplog/mysqldatabasebackup$date.log
###########################################################
#create directory to store mysql database backup
mkdir /var/tmp/mysqldatabasebackup$date
if [ $? -ne 0 ]
then echo "Backup failed with errors" for $date >> /var/tmp/mysqlbackuplog/mysqldatabasebackup$date.log
exit
else
echo “directory mysqldatabasebackup$date created” >> /var/tmp/mysqlbackuplog/mmysqldatabasebackup$date.log
fi
# Back up MySQL databases 2 database name in the anish.txt file
###########################################################
for db in $(cat /root/Desktop/anish.txt)
do
mysqldump -u root -proot $db >> /var/tmp/mysqldatabasebackup$date/$db.sql
echo DUMPING DATABASE FOR CLIENT ""$db"" >> /var/tmp/mysqlbackuplog/mysqldatabasebackup$date.log
echo backup copy of $db is moved to /var/tmp/mysqldatabasebackup$date >> /var/tmp/mysqlbackuplog/mysqldatabasebackup$date.log
cd /var/tmp/mysqldatabasebackup$date
a=`du -sh $db.sql | cut -f1`
echo THE SIZE OF $db.sql FILE IS $a >> /var/tmp/mysqlbackuplog/mysqldatabasebackup$date.log
done
echo "Backup completed successfully $date" >> /var/tmp/mysqlbackuplog/mysqldatabasebackup$date.log
cat /var/tmp/mysqlbackuplog/mysqldatabasebackup$date.log | mail -s "mysqlbackuplog" 07anis@gmail.com
Actually i know the command and all!! dude..but quite confused how to backup the particular
Two databases alone in Regular basis..okay!! Thanks TB0ne..
Last edited by anishkumarv; 06-27-2011 at 10:21 AM.
I got What i expect!!
Actually i know the command and all!!
Then why did you ask the question, if you knew the answer?
Quote:
dude..but quite confused how to backup the particular Two databases alone in Regular basis..okay!! Thanks TB0ne..
If you know how to back up ONE database, you know how to back up ANY databases. Seems like you've already got the script to do it. Does your script WORK, are you asking for help with it?? Not sure why you posed the question, since you said you already knew how to back up a database, and have a script that already seems to (at first glance), work for backing up multiples....
Hi,
checking your script briefly I can say that it doesn't work because of some errors when I tried it on my test server at home.
I'll try to make some corrections (sometimes later) if you want help with your script if it's not working (although marked Solved)?
you can define the database names in a variable in the script like:
Code:
# Back up MySQL databases 2 database name in the anish.txt file
###########################################################
DATABASES="my_first_database
my_2nd-database"
for db in $DATABASES
which would be quite appropriate for this.
DATABASES="1st_name <-- this is deliberately written this way separating the names
2nd_database" <--- as this way the "do" loop will execute as many times you write the names to the DATABASES (you can define 10 or whatever you like)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.