Script to take dump from mysql and send mail
#! /bin/bash
# your MySQL server's name
SERVER=localhost
# directory to backup to
BACKDIR=~/backups
# date format that is appended to filename
DATE=`date +'%m-%d-%Y'`
#----------------------MySQL Settings--------------------#
# your MySQL server's location (IP address is best)
HOST=localhost
# MySQL username
USER=root
# MySQL password
PASS=""
# List all of the MySQL databases that you want to backup in here,
# each separated by a space
DBS="mtv_kbc"
# set to 'y' if you want to backup all your databases. this will override
# the database selection above.
DUMPALL=n
#----------------------Mail Settings--------------------#
# set to 'y' if you'd like to be emailed the backup (requires mutt)
MAIL=y
# email addresses to send backups to, separated by a space
EMAILS="cinu97@gmail.com"
SUBJECT="MySQL backup on $SERVER ($DATE)"
#----------------------FTP Settings--------------------#
# set "FTP=y" if you want to enable FTP backups
FTP=y
# FTP server settings; should be self-explanatory
FTPHOST="localhost"
FTPUSER="root"
FTPPASS="tesync_slt_app"
# directory to backup to. if it doesn't exist, file will be uploaded to
# first logged-in directory
FTPDIR="backups"
#-------------------Deletion Settings-------------------#
# delete old files?
DELETE=n
# how many days of backups do you want to keep?
DAYS=3
#----------------------End of Settings------------------#
# check of the backup directory exists
# if not, create it
if [ -e $BACKDIR ]
then
echo Backups directory already exists
else
mkdir $BACKDIR
fi
if [ $DUMPALL = "y" ]
then
echo "Creating list of all your databases..."
mysql -h $HOST --user=$USER --password=$PASS -e "show databases;" > dbs_on_$SERVER.txt
# redefine list of databases to be backed up
DBS=`sed -e ':a;N;$!ba;s/\n/ /g' -e 's/Database //g' dbs_on_$SERVER.txt`
fi
echo "Backing up MySQL databases..."
for database in $DBS
do
mysqldump -h $HOST --user=$USER --password=$PASS $database > \
$BACKDIR/$SERVER-mysqlbackup-$database-$DATE.sql
gzip -f -9 $BACKDIR/$SERVER-mysqlbackup-$database-$DATE.sql
done
# if you have the mail program 'mutt' installed on
echo "This is automatic script for mysqldump in SLT" | mutt -a "$BACKDIR/$SERVER-mysqlbackup-$database-$DATE.sql.gz" -s "MYSQL dump of SLT" cinu97@gmail.com
Comments
Post a Comment