Mysql database backup script

HI, 
  AutoMySQLBackup with a basic configuration will create Daily, Weekly and Monthly backups of one or more of your MySQL databases from one or more of your MySQL servers.


I am using a script to take a backup of all my databases in the Mysql. After that it will auto move backup to NAS storage.



[root@phpMyfaq ~]# cat /root/Scripts/DB_Backup
#!/bin/bash
##
##This script will take the backup of all
##Database of this server
##
##
######## MYSQL SETUP BACKUP #####
MUSER="root"
MPASS="redhat"
MHOST="localhost"
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
BACKUP="/root/Backup/DB/"
GZIP="$(which gzip)"
NOW=$(date +"%d-%m-%Y")

### Other stuff ###
EMAILID="support@example.com"

##################################

DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"

for db in $DBS;
do
        FILE=$BACKUP/$NOW-$db.gz
        $MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db > $BACKUP/$NOW-$db.sql
        $GZIP $BACKUP/$NOW-$db.sql
done

##### DUMPING BACKUP USING RSYNC #####
##### Where 172.20.1.30 IP address of NAS
  rsync -avz $BACKUP/* 172.20.1.30:/backup/10.125.1.240/db/

##### FIND OUT IF RSYNC BACKUP FAILED OR not ######
if [ "$?" == "0" ]; then
 mv  $BACKUP/* /root/LASTBKP/DB/
 else
 T=/tmp/backup.fail
 echo "Date: $(date)" >$T
 echo "Hostname: $(hostname)" >>$T
 echo "DATA BASE Backup Failed" >>$T
 mail -s "DB Backup Failed $Hostname" "$EMAILID" <$T
 rm -f $T
fi

Comments

  1. Nice blog. Here is the best MySQL database backup script I found. Thanks for sharing valuable content.

    ReplyDelete

Post a Comment

Thank you for visiting my blog.

Popular posts from this blog

Defining Audit Rules

AIX Install packages, upgrade, patching commands

Oracle Database Quick Installation steps 11g Release 2 for Linux x86-64