文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

innobackup增量备份脚本

2024-04-02 19:55

关注
参考涂抹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` ====\n" >> $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}` ====\n" >> ${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 "\n==== Jobs ended at `date +%F' '%T' '%w` ====\n" >> $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` ====\n" >> $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}` ====\n" >> ${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 "\n==== Jobs ended at `date +%F' '%T' '%w` ====\n" >> $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

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     807人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     351人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     314人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     433人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     221人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-数据库
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯