• innobackup增量备份脚本


    参考涂抹mysql里的脚本,做了下改进

    [mysql@mysql01 scripts]$ cat mysql_full_backup_by_xtra.sh
    #!/bin/sh
    # Created by wk

    DATA_PATH=/data/mysqldata/backup/mysql_full
    DATA_FILE=${DATA_PATH}/xtra_fullbak_`date +%Y%m%d%H%M`
    LOG_FILE=${DATA_PATH}/xtra_fullbak_`date +%Y%m%d%H%M`.log
    ORI_CONF_FILE=/data/mysqldata/3306/my.cnf
    NEW_CONF_FILE=${DATA_PATH}/my_3306_`date +%Y%m%d%H%M`.cnf
    MYSQL_PATH=/data/mysqldata/backup/innobackupex/bin
    MYSQL_CMD="${MYSQL_PATH}/innobackupex --user=root --password=pass1 --defaults-file=/data/mysqldata/3306/my.cnf --no-lock --no-timestamp ${DATA_FILE}"

    echo > $LOG_FILE
    echo -e "==== Jobs started at `date +%F' '%T' '%w` ==== " >> $LOG_FILE
    echo -e "==== First cp my.cnf file to backup directory ====" >> $LOG_FILE
    /bin/cp ${ORI_CONF_FILE} ${NEW_CONF_FILE}
    echo >> $LOG_FILE

    #echo -e "**** Executed command:${MYSQL_CMD} | gzip > ${DATA_FILE}" >> $LOG_FILE
    ${MYSQL_CMD} 2>>${LOG_FILE}
    echo -e "**** Executed finished at `date +%F' '%T' '%w` ====" >> $LOG_FILE
    echo -e "**** Backup file size: `du -sh ${DATA_FILE}` ==== " >> ${LOG_FILE}

    echo -e "---- Find expired backup and delete those files ----" >> ${LOG_FILE}
    for tfile in $(/usr/bin/find $DATA_PATH/ -mtime +6)
    do
            if [ -d $tfile ] ; then
                 rmdir $tfile
            elif [ -f $tfile ] ; then
                 rm -f $tfile
            fi
             echo -e "---- Delete tfile: $tfile ----" >> ${LOG_FILE}
    done

    echo -e " ==== Jobs ended at `date +%F' '%T' '%w` ==== " >> $LOG_FILE

    echo "backup_full=${DATA_FILE}" >/data/mysqldata/scripts/backup.conf
    echo "backup_pre_name=${DATA_FILE}" >>/data/mysqldata/scripts/backup.conf

    [mysql@mysql01 scripts]$ cat mysql_incr_backup_by_xtra.sh
    #!/bin/sh
    # Created by wk
    source /data/mysqldata/scripts/backup.conf
    DATA_PATH=/data/mysqldata/backup/mysql_full
    DATA_FILE=${DATA_PATH}/xtra_incrbak_`date +%Y%m%d%H%M`
    #OLD_DATA_FILE=${DATA_PATH}/xtra_fullbak_`date -d "1 days ago" +"%F"`
    LOG_FILE=${DATA_PATH}/xtra_incrbak_`date +%Y%m%d%H%M`.log
    ORI_CONF_FILE=/data/mysqldata/3306/my.cnf
    NEW_CONF_FILE=${DATA_PATH}/my_3306_`date +%Y%m%d%H%M`.cnf
    MYSQL_PATH=/data/mysqldata/backup/innobackupex/bin
    MYSQL_CMD="${MYSQL_PATH}/innobackupex --user=root --password=pass1 --defaults-file=/data/mysqldata/3306/my.cnf --incremental --no-lock --no-timestamp
    --incremental-basedir=${backup_pre_name} ${DATA_FILE}"

    echo > $LOG_FILE
    echo -e "==== Jobs started at `date +%F' '%T' '%w` ==== " >> $LOG_FILE
    echo -e "==== First cp my.cnf file to backup directory ====" >> $LOG_FILE
    /bin/cp ${ORI_CONF_FILE} ${NEW_CONF_FILE}
    echo >> $LOG_FILE

    echo -e "**** Executed command:${MYSQL_CMD} | gzip > ${DATA_FILE}" >> $LOG_FILE
    ${MYSQL_CMD} 2>>${LOG_FILE}
    echo -e "**** Executed finished at `date +%F' '%T' '%w` ====" >> $LOG_FILE
    echo -e "**** Backup file size: `du -sh ${DATA_FILE}` ==== " >> ${LOG_FILE}

    echo -e "---- Find expired backup and delete those files ----" >> ${LOG_FILE}
    for tfile in $(/usr/bin/find $DATA_PATH/ -mtime +6)
    do
            if [ -d $tfile ] ; then
                 rmdir $tfile
            elif [ -f $tfile ] ; then
                 rm -f $tfile
            fi
             echo -e "---- Delete tfile: $tfile ----" >> ${LOG_FILE}
    done

    echo -e " ==== Jobs ended at `date +%F' '%T' '%w` ==== " >> $LOG_FILE

    echo "backup_full=${DATA_FILE}" >/data/mysqldata/scripts/backup.conf
    echo "backup_pre_name=${DATA_FILE}" >>/data/mysqldata/scripts/backup.conf

    [mysql@mysql01 scripts]$ cat backup.conf
    backup_full=/data/mysqldata/backup/mysql_full/xtra_incrbak_201609011805
    backup_pre_name=/data/mysqldata/backup/mysql_full/xtra_incrbak_201609011805

  • 相关阅读:
    zabbix 微信告警
    mongodb 的数据备份与还原
    Templates
    Rsyslog 基本结构
    matplotlib绘图学习
    pyhon 简介
    Pygame (Python编程从入门到实践)
    AttributeError: 'pygame.Surface' object has no attribute 'rect'
    PYTHON CLIENT API
    SALT.STATES.CMD模块
  • 原文地址:https://www.cnblogs.com/godspeed034/p/6807324.html
Copyright © 2020-2023  润新知