此脚本,在01点进行一次逻辑全备份,03点进行一次物理全备份,中午12点进行一次增量物理备份

#! /bin/bash
#05 01,03,12 * * * mysql /data/mysqldata/scripts/mysql_backup_dump_xtra.sh >> /data/mysql/backup/log/mysql_back2.log 2>&1
############################################################
# Define the variables the script used for executing.
#mysql backup by hongquan on 2017
#day=`date +%u`
curHour=`date +%H`
curDate=`date +'%Y%m%d'`
backupDir=/data/mysqldata/backup
defaultFile=/data/mysqldata/backup
mysqlHost=127.0.0.1
port=3306
logicuser=**
logicpass=**
logicalBackupDir=/data/mysqldata/backup/logical
fullBackupDir=/data/mysqldata/backup/full
incBackupDir=/data/mysqldata/backup/inc
logfile=/data/mysqldata/backup/mysql_backup.log
sockfile=/data/mysqldata/3306/mysql.sock full_inbkpex_day=/data/mysqldata/backup/full/full_ipx$curDate$curHour
inc_inbkpex=/data/mysqldata/backup/inc/inc_ipx$curDate$curHour MYSQL_PATH=/usr/local/mysql/bin
MYSQL_CMD="${MYSQL_PATH}/mysql -u${logicuser} -p${logicpass} -h${mysqlHost} -S /data/mysqldata/${HOST_PORT}/mysql.sock"
MYSQL_DUMP="${MYSQL_PATH}/mysqldump -u${logicuser} -p${logicpass} -h${mysqlHost} -P${HOST_PORT} -R -S \
${sockfile} --single-transaction --master-data=2 --default-character-set=utf8 --set-gtid-purged=OFF -q " case ${curHour} in
01)
type=logical
;;
03)
type=full
;;
12)
type=inc
;;
"*")
exit
esac echo "NOW is : Backup type=$type" >> ${logfile} if [ ! -d "${backupDir}" ]; then
mkdir -p "${backupDir}"
echo -e "===${backupDir} does not exsits,created them!" >> ${logfile}
fi if [ ! -d "${logicalBackupDir}" ]; then
mkdir -p "${logicalBackupDir}"
echo -e "===${logicalBackupDir} does not exsits,created them!" >> ${logfile}
fi if [ ! -d "${fullBackupDir}" ]; then
mkdir -p "${fullBackupDir}"
echo -e "===${fullBackupDir} does not exsits,created them!" >> ${logfile}
fi if [ ! -d "${incBackupDir}" ]; then
mkdir -p "${incBackupDir}"
echo -e "===${incBackupDir} does not exsits,created them!" >> ${logfile}
fi extra_lsndir=${backupDir}
ori_conf_file=/data/mysqldata/${port}/my.cnf
new_conf_file=${backupDir}/my_${port}_`date +%Y%m%d%H%M%S`.cnf echo "backup start" `date` >> ${logfile}
echo -e "===first cp my.cnf file to backup directory ===" >> ${logfile}
/bin/cp ${ori_conf_file} ${new_conf_file} echo >> ${logfile} if [[ "${type}" = "logical" ]]; then
# -------------------------- logical backup with mysqldump --------------------------
echo -e "mysqldumpbk per db list= ${list} " >> ${logfile}
for dbs in `${MYSQL_CMD} 2>/dev/null -e "show databases" | sed '1d' | egrep -v "information_schema|performance_schema|sys"`
do
echo -e "echo $dbs is appoint ; " >> ${logfile}
${MYSQL_DUMP} ${dbs} 2>/dev/null | gzip > ${logicalBackupDir}/${dbs}_${curDate}.sql.gz
echo -e " **** database :${dbs} backup stop_time :`date +%F' '%T' '%w` **** \n">> ${logfile}
echo -e "**** backup file size:`du -sh ${logicalBackupDir}/`**** \n" >> ${logfile}
done
elif [[ "${type}" = "full" ]]; then
# -------------------------- full backup with xtrabackup --------------------------
cd ${backupDir}
#rm -rf /data/mysql/backup/full/
if [ ! -d "${full_inbkpex_day}" ]; then
mkdir -p "${full_inbkpex_day}"
echo -e "===${full_inbkpex_day} does not exsits,created them!" >> ${logfile}
fi
#tar -zcvf $tar_full.tar.gz ${full_inbkpex_day}
cd ${full_inbkpex_day} /usr/bin/innobackupex --defaults-file=${ori_conf_file} --user=${logicuser} --password=${logicpass} \
--host=${mysqlHost} --port=${port} --no-timestamp --extra-lsndir=${extra_lsndir} --stream=tar ${backupDir} \
2>/tmp/full_ipx$curDate$curHour.log | gzip 1>${full_inbkpex_day}/`date +%Y%m%d%H%M%S`.tar.gz echo -e "mysql full backup full_ipx$curDate$curHour" >> ${logfile} elif [[ "${type}" = "inc" ]]; then
# -------------------------- incremental backup with xtrabackup --------------------------
if [ ! -d "${inc_inbkpex}" ]; then
mkdir -p "${inc_inbkpex}"
echo -e "===${inc_inbkpex} does not exsits,created them!" >> ${logfile}
fi
/usr/bin/innobackupex --defaults-file=${ori_conf_file} --user=${logicuser} --password=${logicpass} \
--host=${mysqlHost} --port=${port} --no-timestamp --extra-lsndir=${extra_lsndir} --incremental \
--incremental-basedir=${backupDir} ${inc_inbkpex} 2>/tmp/inc_ipx$curDate$curHour.log
echo -e "mysql inc backup inc_ipx$curDate$curHour" >> ${logfile}
else
echo -e "wrong backup type!" >> ${logfile}
exit 1
fi #echo -e "----find expired backup and delete those files ----">> ${logfile}
#for tfile in $(/usr/bin/find ${backupDir}/ -mtime +7)
#do
# if [ -d $tfile ] ; then
# rmdir $tfile
# elif [ -f $tfile ]; then
# #rm -f $tfile
# echo -e "---not backupDir found ----">> ${logfile}
# fi
# echo -e "----delete file:$tfile ----">> ${logfile}
#done echo -e "\n=== backup dened at `date +%F' '%T' '%w`===\n" >> ${logfile}

MySQL mysqldump与innobackupex 组合备份的更多相关文章

  1. 配合crond服务实现自定义周期备份MySQL数据库(使用innobackupex进行备份)

    备份 新建一个脚本/root/backup.py,内容如下: #!/usr/bin/env python# -*- coding: utf-8 -*- ''' 脚本作者:昨夜星辰 脚本作用:配合cro ...

  2. c# Process cmd 执行完回调 Proc_OutputDataReceived mysql mysqldump mysql source备份还原数据

    c# Process 执行完回调 Proc_OutputDataReceived mysql mysqldump mysql source备份还原数据 直接贴代码 前提:mysql5.7 vs2017 ...

  3. 使用mysql自带工具mysqldump进行全库备份以及source命令恢复数据库

    mysql数据库提供了一个很好用的工具mysqldump用以备份数据库,下面将使用mysqldump命令进行备份所有数据库以及指定数据库 一.mysqldump一次性备份所有数据库数据 /usr/lo ...

  4. [MySQL] innobackupex在线备份及恢复(全量和增量)

    安装percona-xtrabackup 方法1: percona-xtrabackup-2.1.9-744-Linux-x86_64.tar.gz(D:\share\src\linux-mysql) ...

  5. mysql 针对单张表的备份与还原

    A.MySQL 备份工具xtrabackup 的安装 . percona 官方xtrabackup 的二进制版本:二进制版本解压就能用了. . 解压xtrabackup & 创建连接 -Lin ...

  6. mysql用户授权及数据备份恢复

    用户授权与权限撤销 修改数据库管理员从本机登陆的密码测试: mysqladmin -hlocalhost -uroot -p password "新密码" Enter passwo ...

  7. 【转】mysqldump与innobackupex知多少

    作者:罗小波 [目录] 1. 先看mysqldump 1.1 mysqldump备份过程解读 1.2 mysqldump备份过程中的关键步骤 1.2.1 FLUSH TABLES和FLUSH TABL ...

  8. mysqldump与innobackupex备份过程你知多少

    mysqldump与innobackupex备份过程你知多少 测试库表创建(这里在同一个库下创建两个表,一个表为innodb引擎,一个为myisam引擎) root@localhost : (none ...

  9. MySQL 分区表原理及数据备份转移实战

    MySQL 分区表原理及数据备份转移实战 1.分区表含义 分区表定义指根据可以设置为任意大小的规则,跨文件系统分配单个表的多个部分.实际上,表的不同部分在不同的位置被存储为单独的表.用户所选择的.实现 ...

随机推荐

  1. struts2数据类型转换详解

    Web应用程序的交互都是建立在HTTP之上的,互相传递的都是字符串.也就是说服务器接收到的来自用户的数据只能是字符串或者是字符数组,而在Web应用的对象中,往往使用了多种不同的类型,如整数(int). ...

  2. windows编译hadoop 2.x Hadoop-eclipse-plugin插件

    本文转载至:http://blog.csdn.net/congcong68/article/details/42098391 一.简介 Hadoop2.x之后没有Eclipse插件工具,我们就不能在E ...

  3. UVA 12307 Smallest Enclosing Rectangle(旋转卡壳)

    题意:给你一些点,找出两个可以包含所有点的矩形,一个保证矩形面积最小,一个保证矩形周长最小,输出两个最小值 题解:首先根据所有点求一个凸包,再在这个凸包上枚举每条边,作为矩形的一条边(这样可以保证最小 ...

  4. 直播P2P技术3-伙伴节点质量评估及子流订阅

    以上模型,暂且称之为W-P2P吧.

  5. Delphi_检查exe文件是否是"随机基址"

    ZC: cnpack 还是蛮好用的 1.代码: procedure TForm1.btnRandomizedBaseAddressClick(Sender: TObject); var pDosHdr ...

  6. 【转载】JAVA中线程的两种实现方法-实现Runnable接口和继承Thread类

    转自: http://blog.csdn.net/sunguangran/article/details/6069317 非常感谢原作者,整理的这么详细. 在java中可有两种方式实现多线程,一种是继 ...

  7. python快速学习-常用內建模块

  8. PyCharm 的升级、设置快捷方式

    05. PyCharm 的升级以及其他 PyCharm 提供了对 学生和教师免费使用的版本 教育版下载地址:https://www.jetbrains.com/pycharm-edu/download ...

  9. 《Advanced Bash-scripting Guide》学习(十八):[[ ]]与[ ]的一些特殊情况

    本文所选的例子来自于<Advanced Bash-scripting Gudie>一书,译者 杨春敏 黄毅 例1: [ -eq ] && [ -n "`echo ...

  10. javascript queue 打字效果

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...