You are on page 1of 1

MYSQL_BIN=/usr/bin/

# Information for logging in to mysql


MYSQL_USER='root'
MYSQL_PASS='b@@k$123123!'
# Array of the Databases separated by spaces and
# their minimum backup size (compressed)
MYSQL_DATABASES=`mysql -u $MYSQL_USER --password="$MYSQL_PASS" -s -e "show datab
ases"`
declare -a MYSQL_DATABASES
BACKUP_DIR=/mysqlbackups

############################################################################
# END OF USER DEFINED
############################################################################
#CURRENT DATE
DT=`date +%G%m%d`
#Linux cp -i will break binlog shipping
unalias -a

count=0
for i in ${MYSQL_DATABASES[*]}; do
# Full backups should not be done more then once a day
# If they are, we going create another with Hour Min Sec
if [ -a "$BACKUP_DIR/$i.full.$DT.sql.gz" ];then
DT=`date +%G%m%d-%H%M%S`
fi
if [ $i != 'mysql' ] && [ $i != 'test' ] && [ $i != 'lost+found'
] && [ $i != 'information_schema' ]; then
## For Innodb & DBD backups add --single-transaction to
exclude table locking for duration of the backup
$MYSQL_BIN/mysqldump -u $MYSQL_USER --password="$MYSQL_P
ASS" -B $i --hex-blob --opt --single-transaction | /bin/gzip > $BACKUP_DIR/$i
.full.$DT.sql.gz
else
if [ $i != 'test' ] && [ $i != 'lost+found' ] && [ $i !
= 'information_schema' ]; then
## For MyISAM or Mix : Innodb & MyISAM & DBD
$MYSQL_BIN/mysqldump -u $MYSQL_USER --password="$MYSQL_P
ASS" -B $i --hex-blob --opt | /bin/gzip > $BACKUP_DIR/$i.full.$DT.sql.gz
fi
fi
let count++
done

You might also like