mysql 备份脚本

全量备份:

#!/bin/bash
#mysql全量备份脚本
#mkdir/backup
cd/backup
dateDIR=`date+"%y-%m-%d"`
mkdir-p$dateDIR/data
path=/var/lib/mysql
foriin`mysql-uroot-p123456-e"showdatabases"|grep-v"Database"`
do
mysqldump-uroot-p123456--opt$i--skip-lock-tables|gzip>/backup/$dateDIR/data/${i}_${dateDIR}.sql.gz
done

mysqladmin-uroot-p123456flush-logs
binlog_rm=`tail-n1$path/mysql-bin.index|sed's/.\///'`
mysql-uroot-p123456-e"purgebinarylogsto'$binlog_rm'"
~

增量备份:


#!/bin/bash
#mysql增量备份脚本

cd/backup
dateDIR=`date+"%y-%m-%d"`
mkdir-p$dateDIR/data
path=/var/lib/mysql
mysqladmin-uroot-p123456flush-logs
binlog_cp=`head-n-1$path/mysql-bin.index|sed's/.\///'`
foriin$binlog_cp
do
mysql-uroot-p123456-e"FLUSHTABLESWITHREADLOCK;\!cp-p$path/$i/backup/$dateDIR/data/;"
done

binlog_rm=`tail-n1$path/mysql-bin.index|sed's/.\///'`
mysql-uroot-p123456-e"purgebinarylogsto'$binlog_rm'"

你可能感兴趣的:(mysql,备份脚本)