#
echo "/PATH/mysqlbak.sh -f: You can backup all databases"
echo "/PATH/mysqlbak.sh -i: Just backup the exter change from the last backup"
echo "/PATH/mysqlbak.sh -d: Backup from the last full-backup to the current time"
}
mysql -e "FLUSH TABLES WITH READ LOCK;"
mysql -e "SHOW MASTER STATUS;">/dev/null
startfile=/tmp/startposition
exterfile=/tmp/exterposition
case $OPTS in
f)
mysqldump --all-databases >/mybackup/db.$DATE
STARTPOSITION=`mysql -e "SHOW MASTER STATUS;" | tail -1 | awk '{print $2}'>$startfile`
ESTARTPOSITION=`mysql -e "SHOW MASTER STATUS;" | tail -1 | awk '{print $2}'>$exterfile`
cd /mybackup
tar -cjf /root/bakmysql/db.$DATE.tar.gz2 db.$DATE >/dev/null
;;
d)
mysql -e "FLUSH TABLES WITH READ LOCK;"
mysql -e "SHOW MASTER STATUS;">/dev/null
FILE=`mysql -e "SHOW MASTER STATUS;" | tail -1 | awk '{print $1}'`
STARTPOSITION=`cat $startfile`
ENDPOSITION=`mysql -e "SHOW MASTER STATUS;" | tail -1 | awk '{print $2}'`
mysqlbinlog --start-position $STARTPOSITION --stop-position $ENDPOSITION /mydata/data/$FILE >/mybackup/incre.$DATE
cd /mybackup
tar -cjf /root/bakmysql/incre.$DATE.tar.gz2 incre.$DATE >/dev/null
;;
i)
mysql -e "FLUSH TABLES WITH READ LOCK;"
mysql -e "SHOW MASTER STATUS;">/dev/null
FILE=`mysql -e "SHOW MASTER STATUS;" | tail -1 | awk '{print $1}'`
EENDPOSITION=`mysql -e "SHOW MASTER STATUS;" | tail -1 | awk '{print $2}' >>$exterfile`
ESTARTPOSITION=`tail -n 2 $exterfile | head -n 1`
Exendposition=`tail -n 1 $exterfile`
mysqlbinlog --start-position $ESTARTPOSITION --stop-position $Exendposition /mydata/data/$FILE >/mybackup/exter.$DATE
cd /mybackup
tar -cjf /root/bakmysql/exter.$DATE.tar.gz2 exter.$DATE >/dev/null
;;
h)
HELPTXT
;;
esac
done