mysql backup – shell script


Situation : To create a critical database backup through shell script.

Solution: Create a file mysqlback.sh and copy the below script into that file. Give excute permission(# chmod a+x mysqlback.sh) to excute that mysqlback.sh  file.

#/bin/bash
###Intitiate mysql backup####

echo “Mysql-Backup-job initiated”

MUSER=”your user name”
MHOST=”your host”
MPASS=”your password”
LOGFILE=/root/mysqlback.log (Eg., put appropriate path for the log file according to your requirement)

mysqldump -u$MUSER -h$MHOST  -p$MPASS database name  > /home/karthick/filename.sql

###create a timestamo in a logfile.

date >> $LOGFILE

echo “Mysql-Backup Completed” >> $LOGFILE
exit

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: