zoukankan      html  css  js  c++  java
  • 亚马逊 RDS binlog日志 拉取到本地 脚本

    #!/bin/sh
    BACKUP_BIN=/usr/bin/mysqlbinlog
    LOCAL_BACKUP_DIR=/dir1/dir2/
    BACKUP_LOG=/dir1/dir2/backuplog

    REMOTE_HOST=yourhost
    REMOTE_PORT=3306
    REMOTE_USER=youruser
    REMOTE_PASS=yourpasswd
    FIRST_BINLOG=mysql-bin-changelog.010105

    #time to wait before reconnecting after failure
    SLEEP_SECONDS=10

    ##create local_backup_dir if necessary
    mkdir -p ${LOCAL_BACKUP_DIR}
    cd ${LOCAL_BACKUP_DIR}

    ## 运行while循环,连接断开后等待指定时间,重新连接
    while :
    do
    if [ `ls -A "${LOCAL_BACKUP_DIR}" |wc -l` -eq 0 ];then
    LAST_FILE=${FIRST_BINLOG}
    else
    LAST_FILE=`ls -l ${LOCAL_BACKUP_DIR} | grep -v backuplog |tail -n 1 |awk '{print $9}'`
    fi
    ${BACKUP_BIN} --raw --read-from-remote-server --stop-never --host=${REMOTE_HOST} --port=${REMOTE_PORT} --user=${REMOTE_USER} --password=${REMOTE_PASS} --result-file=${LOCAL_BACKUP_DIR} ${LAST_FILE}

    echo "`date +"%Y/%m/%d %H:%M:%S"` mysqlbinlog停止,返回代码:$?" | tee -a ${BACKUP_LOG}
    echo "${SLEEP_SECONDS}秒后再次连接并继续备份" | tee -a ${BACKUP_LOG}
    sleep ${SLEEP_SECONDS}
    done

  • 相关阅读:
    vue 相对其他热门 框架 优点 --- 待续
    vue router 只需要这么几步
    正则表达式
    MySQL数据库优化的八种方式
    Django REST Framework 最佳实践
    Node.js ZLIB
    Node.js 虚拟机
    Node.js 实用工具
    Node.js URL
    Node.js UDP/Datagram
  • 原文地址:https://www.cnblogs.com/ligang0357/p/11188342.html
Copyright © 2011-2022 走看看