MySQL分库备份脚本 # cat /scripts/mysql_store_backup.sh
#!/bin/bash MYPASS="123456" SOCKET=/tmp/mysql.sock MYLOGIN="mysql -uroot -p$MYPASS -S $SOCKET" MYDUMP="mysqldump -uroot -p$MYPASS -S $SOCKET -B --single-transaction --all-databases --flush-logs" DATABASE="$($MYLOGIN -e "show databases;" |egrep -vi "Data|_schema|mysql")" for dbname in $DATABASE do MYDIR=/backup/$dbname [ -d $MYDIR ] || mkdir -p $MYDIR $MYDUMP $dbname|gzip >$MYDIR/${dbname}_$(date +%F).sql.gz done
MySQL分库分表备份脚本 # cat /scripts/mysql_table_backup.sh
#/bin/bash MYPASS="123456" SOCKET=/tmp/mysql.sock MYLOGIN="mysql -uroot -p$MYPASS -S $SOCKET" MYDUMP="mysqldump -uroot -p$MYPASS -S $SOCKET -B --single-transaction --all-databases --flush-logs" DATABASE="$($MYLOGIN -e "show databases;" |egrep -vi "Data|_schema|mysql")" for dbname in $DATABASE do TABLE="$($MYLOGIN -e "use $dbname;show tables;" |sed '1d')" for tname in $TABLE do MYDIR=/backup/$dbname [ -d $MYDIR ] || mkdir -p $MYDIR $MYDUMP $dbname $tname|gzip >$MYDIR/${dbname}_${tname}$(date +%F).sql.gz done done
MySQL增量备份脚本,(增量备份是基于 binlog 日志的) # cat /scripts/mysql_zl_back.sh
#/bin/bash MYPASS="123456" mysql -uroot -p$MYPASS -e "flush logs;"
转载于:https://blog.51cto.com/10494588/1737013