【linux命令】分别基于innobackupex备份工具的mysql全量备份和增量备份shell脚本
内容摘要
#!/bin/bash
#author:21yunwei
logfile="/home/mysqlbak/mysql_full_bak_time.log"
backuplogfile="/home/mysqlbak/mysqlbackup.log"
mysql_bakdir="/home/mysqlbak/"
user
#author:21yunwei
logfile="/home/mysqlbak/mysql_full_bak_time.log"
backuplogfile="/home/mysqlbak/mysqlbackup.log"
mysql_bakdir="/home/mysqlbak/"
user
文章正文
#!/bin/bash #author:21yunwei logfile="/home/mysqlbak/mysql_full_bak_time.log" backuplogfile="/home/mysqlbak/mysqlbackup.log" mysql_bakdir="/home/mysqlbak/" user=root password=xxxxxx [ ! -d $mysql_bakdir ] && mkdir -p $mysql_bakdir [ ! -f $logfile ] && touch $logfile innobackupex --defaults-file=/etc/my.cnf --user=${user} --password=${password} --compress –-parallel=4 –-throttle=400 --stream=tar ${mysql_bakdir} 2>&1 >> $backuplogfile reset=$? finishtime=`date +%Y%m%d_%H%M%S` [ ${reset} -eq 0 ] && echo "Mysql fullbakup finished, time: $finishtime">> $logfile || echo "Mysql fullbakup failed,please check time:$finishtime" >> $logfile
mysql增量备份脚本如下:
#!/bin/bash #author:21yunwei time=`date -d '-3 day' +%Y-%m-%d` logfile="/home/mysqlbak/mysql_full_bak_time.log" mysql_bakdir="/home/mysqlbak/" user=root password=xxxxxx lastfullbakdir=`ls /home/mysqlbak/ |grep ${time}` [ ! -d $mysql_bakdir ] && mkdir -p $mysql_bakdir [ ! -d $logfile ] && touch $logfile innobackupex --defaults-file=/etc/my.cnf --user=${user} --password=${password} --incremental-basedir=${mysql_bakdir}/${lastfullbakdir} --incremental ${mysql_bakdir} finishtime=`date +%Y%m%d_%H%M%S` [ $? -eq 0 ] && echo "Mysql fullbakup finished, time: $finishtime">> $logfile || echo "Mysql fullbakup failed,please check time:$finishtime">> $logfile
代码注释
[!--zhushi--]