Skip to main content

Posts

Showing posts from 2015

MySQL backup using shell script mysqldump utility

#!/bin/bash # Error handling function error() { echo -e "[ `date` ] $(tput setaf 1)$@$(tput sgr0)" exit $2 } ### Set Bins Path ### RM=/bin/rm GZIP=/bin/gzip GREP=/bin/grep MKDIR=/bin/mkdir MYSQL=/usr/bin/mysql MYSQLDUMP=/usr/bin/mysqldump MYSQLADMIN=/usr/bin/mysqladmin ### Enable Log = 1 ### LOGS=1 ### Default Time Format ### TIME_FORMAT='%d%b%Y%H%M%S' ### Setup Dump And Log Directory ### MYSQLDUMPPATH=/var/www/mysqldump MYSQLDUMPLOG=/var/log/mysqldump.log EXTRA_PARAMS=$1 ##################################### ### ----[ No Editing below ]------### ##################################### [ -f ~/.my.cnf ] || error "Error: ~/.my.cnf not found" ### Make Sure Bins Exists ### verify_bins(){ [ ! -x $GZIP ] && error "File $GZIP does not exists. Make sure correct path is set in $0." [ ! -x $MYSQL ] && error "File $MYSQL does not exists. Make sure correct path is set in $0." [ ! -x $MYSQLDUMP ] && error "Fil...