zoukankan      html  css  js  c++  java
  • mysql 备份脚本

    #!/bin/bash
    # 要备份的数据库名'多个数据库用空格分开
    databases=(  basedata os-data os-ues policy_manage  datadb  uee enn_fnt etsp fannengdb filedb fnw-boss riet rules busi uac wit-operation mysql pvsdb pvs-datadb )
    # 备份文件要保存的目录
    basepath='/data/backup/'
    if [ ! -d "$basepath" ]; then
      mkdir -p "$basepath"
    fi
    # 循环databases数组
    for db in ${databases[*]}
      do
       # 备份数据库生成SQL文件
    /usr/local/mysql/bin/mysqldump -umha  -p'admin+1234'  -h10.39.41.111 --default-character-set=utf8 -R  --triggers  --events --opt  --hex-blob --single-transaction  --master-data=1 $db 2>/dev/null | gzip  >$basepath$db-$(date +%Y%m%d-%H).sql.gz
    #/usr/local/mysql/bin/mysqldump -umha  -p'admin+1234'   --default-character-set=utf8 -R  --triggers  --events --opt   --set-gtid-purged=on --hex-blob --single-transaction --dump-slave=2 $db 2>/dev/null | gzip  >$basepath$db-$(date +%Y%m%d-%H%M%S).sql.gz
    FILE_NAME="$db-$(date +%Y%m%d-%H).sql.gz" #最终保存的数据库备份文件名
    FILE=${basepath}${FILE_NAME}
    
    #echo "$FILE"
    
    # 判断当天备份文件是否生成
    if [ ! -f "$FILE" ];
    then
          echo "####### $DATA #########">> /data/backup/mysql_bak.err
          echo "MySQL back up $IP hava not created!" >>    /data/backup/mysql_bak.err
          echo "MySQL back up $IP hava not created!" | mail -s "WARN! MySQL back up $IP $FILE hava not created!" DbaAdmin@enn.cn
    elif [ `ls -s $FILE|awk '{print $1}'` -lt 15 ];
    then
          echo "####### $DATA #########">> /data/backup/mysql_bak.err
          echo "MySQL back up $IP hava created,but file is not greater than 15kB!" >>    /data/backup/mysql_bak.err
          echo "MySQL back up $IP hava created,but file is not greater than 15kB!" | mail -s "WARN! MySQL back up $IP $FILE hava failed!" DbaAdmin@enn.cn
    else
          echo "MySQL back up  $FILE have exist!"
          echo "MySQL back up successful!"
    fi
    
     done
    # 删除天之前的备份数据
    find $basepath -mtime +30 -name "*.sql.gz" -exec rm -rf {} ;
  • 相关阅读:
    Ubuntu18.04+windows10双系统时间同步教程
    Ubuntu官方源
    Ubuntu 16.04下OLSR协议安装教程
    Ubuntu 18.04中的Vim编辑器的高级配置
    关于vue-cli的安装
    var与let、const的区别
    jq点击相册弹出弹窗并可以轮播相册效果
    css三角形上下左右实心空心尖角箭头
    leetcode-44. Wildcard Matching
    c++转换构造函数和类型转换函数
  • 原文地址:https://www.cnblogs.com/kcxg/p/10724852.html
Copyright © 2011-2022 走看看