zoukankan      html  css  js  c++  java
  • mysql全备、增量备份脚本

     1.mysql全量备份及定时删除备份文件脚本
    #!/bin/bash
    v_user="root"
    v_password="mysql"
    backup_date=`date +%Y%m%d%H%M`
    mysqldir=/usr/local/mysql
    full_backup=/mysql/data/full_backup
    mkdir -p $full_backup/$backup_date
    $mysqldir/bin/mysqldump -u$v_user -p$v_password --single-transaction --master-data=2 -A -R -E --triggers --flush-logs>$full_backup/$backup_date/full_backup.sql
    gzip $full_backup/$backup_date/full_backup.sql
    find /mysql/data/full_backup -name "full_backup.*" -mtime +30 -type f | xargs rm -f
    
     
    2.mysql增量备份及定时删除增量备份文件脚本
    #!/bin/bash
    v_user="root"
    v_password="mysql"
    mysqldir=/usr/local/mysql
    incre_backup=/mysql/data/incre_backup
    mkdir -p $incre_backup
    $mysqldir/bin/mysqladmin -u$v_user -p$v_password flush-logs
    find /mysql/binlog -name "mysql-bin.*" -mtime -1 -type f  | xargs -i  cp {} $incre_backup
    find /mysql/data/incre_backup -name "mysql-bin.*" -mtime +30 -type f | xargs rm -rf
    
     
    3.mysql开启binlog
     查看是否开启binlog:
    mysql> show variables like 'log_bin';
    +---------------+-------+
    | Variable_name | Value |
    +---------------+-------+
    | log_bin       | ON    |
    +---------------+-------+
     
    value为on,则说明已经开启binlog
    value为off,则说明未开启binlog
     
    如何开启binlog?
    修改MySQL参数文件my.cnf
    vi my.cnf
    log_bin=/data/3306/binlog/mysql‐bin
     
    重启MySQL
    show variables like 'log_bin';
    +---------------+-------+
    | Variable_name | Value |
    +---------------+-------+
    | log_bin       | ON    |
    +---------------+-------+
    

      

     
     
  • 相关阅读:
    在线教育项目-day02【讲师分页功能和多条件组合查询功能】
    在线教育项目-day02【统一结果返回】
    Go语言数组和切片的原理
    Go语言单元测试与基准测试
    PHPWord导出word文档
    Go语言反射reflect
    漫画:什么是HTTPS?
    什么是shell和终端?
    Go接口interface
    Go变量逃逸分析
  • 原文地址:https://www.cnblogs.com/orcl-2018/p/12613343.html
Copyright © 2011-2022 走看看