使用mysqldump实现全备,增备的脚本

更多博文请关注:没有伞的孩子必须努力奔跑 (www.xuchanggang.cn)

mysqldump实现增备,其实就是复制日志

全备脚本:

#! /bin/bash

# mysql 全量备份脚本,建议在slave上运行,并开启log_slave_updates=1

mkdir /backup

cd /backup

datadir=`date +"%y-%m-%d"`

mkdir -p $datadir/data

path=/usr/local/mysql/data

for i in `mysql -uroot -p123456 -e "show databases" |grep  -v "Database"`

do

  mysqldump -uroot -p123456 --defaultes-character-set=utf8 -q --lock-all-tables --flush-logs -E -R --triggers -B $i |gzip > /backup/$datadir/data/${i}_${datadir}.sql.gz

  #mysqldump -uroot -ptiancity --opt --single-transaction  --flush-logs -E -R -C --triggers  $i |gzip > "/backup/$datadir/data/${i}_${datadir}.sql.gz"

done

binlog_rm=`tail -n 1 /app/mysql/data/mysql-bin.index |sed 's/\/app\/mysql\/data\///'`

mysql -uroot -p123456 -e "purge binary logs to '$binlog_rm'"

增备脚本:

#! /bin/bash

# mysql 增量备份脚本,其实就是复制二进制日志,

cd /backup

datadir=`date +"%y-%m-%d"`

mkdir -p $datadir/data

path=/usr/local/mysql/data

mysqladmin -uroot -p12334 flush-logs

# mysql -uroot -p12334 -e "flush logs"

binlog_cp=`head -n -1 $path/mysql-bin.index |sed 's/\/app\/mysql\/data\///'`

for  i in $binlog_cp

do

   cp $path/$i /backup/$datadir/data/

done

binlog_rm=`tail -n 1 /app/mysql/data/mysql-bin.index |sed 's/\/app\/mysql\/data\///'`

mysql -uroot -p12334 -e "purge binary logs to '$binlog_rm'"



你可能感兴趣的:(mysql,dump,全备增备)