urce /root/.bash_profile
today=`date +"%Y_%m_%d"`
bkdir=/opt/new data
today_bkdir=$bkdir/$today
cd $bkdir
if [ ! -d $today_bkdir ] ; then
mkdir -p $today_bkdir
fi
DATE=`date +%Y%m%d_%H%M`
mysqldump -p123456 --flush-logs --master-data=2 --single-transaction -R --triggers newdb --default-character-set=utf8 > $today_bkdir/360 $DATE.sql
LFILE=`mysql -uroot -p123456 -e "show binary logs"|grep "mysql-bin"|awk 'END {print $1}'`
cd $today_bakdir
find $bkdir -type d -mtime +3 -maxdepth 1 -exec rm -rf {} \;
方法二:
#!/bin/sh
source /root/.bash_profile
today=`date +"%Y_%m_%d"`
bkdir=/opt/ data
today_bkdir=$bkdir/$today
cd $bkdir
if [ ! -d $today_bkdir ] ; then
mkdir -p $today_bkdir
fi
MYSQL_CONN="-uroot -p123456 "
mysql ${MYSQL_CONN} -A -e"FLUSH TABLES WITH READ LOCK; SELECT SLEEP(86400)" &
sleep 3
mysql -uroot -padmin -e "show master status;"
mysql -uroot -padmin -e "show slave status\G;"
rsync --recursive /opt/data $today_bkdir
mysql -uroot -padmin -e "show slave status\G;"
mysql -uroot -padmin -e "show master status;"
SLEEP_ID=`mysql ${MYSQL_CONN} -A -e"SHOW PROCESSLIST;" | grep "SELECT SLEEP(86400)" | awk '{print $1}'`
mysql ${MYSQL_CONN} -A -e"KILL ${SLEEP_ID}"
cd $today_bakdir
find $bkdir -type d -mtime +2 -maxdepth 1 -exec rm -rf {} \;
today=`date +"%Y_%m_%d"`
bkdir=/opt/new data
today_bkdir=$bkdir/$today
cd $bkdir
if [ ! -d $today_bkdir ] ; then
mkdir -p $today_bkdir
fi
DATE=`date +%Y%m%d_%H%M`
mysqldump -p123456 --flush-logs --master-data=2 --single-transaction -R --triggers newdb --default-character-set=utf8 > $today_bkdir/360 $DATE.sql
LFILE=`mysql -uroot -p123456 -e "show binary logs"|grep "mysql-bin"|awk 'END {print $1}'`
cd $today_bakdir
find $bkdir -type d -mtime +3 -maxdepth 1 -exec rm -rf {} \;
方法二:
#!/bin/sh
source /root/.bash_profile
today=`date +"%Y_%m_%d"`
bkdir=/opt/ data
today_bkdir=$bkdir/$today
cd $bkdir
if [ ! -d $today_bkdir ] ; then
mkdir -p $today_bkdir
fi
MYSQL_CONN="-uroot -p123456 "
mysql ${MYSQL_CONN} -A -e"FLUSH TABLES WITH READ LOCK; SELECT SLEEP(86400)" &
sleep 3
mysql -uroot -padmin -e "show master status;"
mysql -uroot -padmin -e "show slave status\G;"
rsync --recursive /opt/data $today_bkdir
mysql -uroot -padmin -e "show slave status\G;"
mysql -uroot -padmin -e "show master status;"
SLEEP_ID=`mysql ${MYSQL_CONN} -A -e"SHOW PROCESSLIST;" | grep "SELECT SLEEP(86400)" | awk '{print $1}'`
mysql ${MYSQL_CONN} -A -e"KILL ${SLEEP_ID}"
cd $today_bakdir
find $bkdir -type d -mtime +2 -maxdepth 1 -exec rm -rf {} \;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/90618/viewspace-1073760/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/90618/viewspace-1073760/