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    |
+---------------+-------+

  

 
 
posted @ 2020-04-01 16:13  orcl  阅读(172)  评论(0编辑  收藏  举报