# #注意各种目录创建及相关参数设置
# #设置/root/dba/binlog_control。txt,记录binlog文件时间,获取时间命令:y mysql_mmm_01-bin stat - c %。000013年
# #设置/root/dba/fullbak_file.txt,记录全备目录,第一次执行时,需设置一个目录来存放备份前产生的binlog,之后每次全备会自动更新该文件
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -full_backup: mysql_full_backup.sh - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# !/bin/bash
# mysql用户参数
="根"
passwd=" 123456 "
套接字="/数据/mysql/运行/mysql。袜子”
=3306港
bk_options="——单独的事务——flush-logs - u $ user - p passwd美元——主数据=https://www.yisu.com/zixun/2,所有数据库——套接字=$套接字端口=$端口”
#日志文件dtime=Y '日期+ % % m % d % H % m % S的
log_base="/根/dba/日志”
log_file=" $ log_base/full_backup_ $ {dtime}。日志”
#控制文件
contr_file="/根/dba/binlog_control.txt”
fullbak_file="/根/dba/fullbak_file。txt”
#完整备份dir
bk_dir_suffix=叭掌? % Y % m % d”
full_dir="/备份/mysql_bak/mysql_ bk_dir_suffix美元”
[- d $ {full_dir}] | | mkdir - p $ {full_dir}
回声”mkdir完整备份dir: $ full_dir ",祝辞的在美元log_file
#完整备份文件
full_bk_file=" mysql_full_ bk_dir_suffix美元。sql”
#, mysqldump cd $ full_dir
, mysqldump bk_options比美元;美元full_bk_file
回声“完整备份文件:$ full_bk_file”在祝辞美元log_file
#前一次完整备份备份日志——binlog刷新到
/根/dba/mysql_binlog_backup_new。sh
# fullbak_file更新控制文件
echo $ full_dir比;美元fullbak_file
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -binlog_backup: mysql_binlog_backup_new.sh - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# !/bin/bash
# mysql用户=
“根”passwd=" 123456 "
套接字="/数据/mysql/运行/mysql。袜子”
=3306港
#日志文件dtime=Y '日期+ % % m % d % H % m % S的
log_base="/根/dba/日志”
log_file=" $ log_base/binlog_backup_ $ {dtime}。日志”
#控制文件
contr_file="/根/dba/binlog_control.txt”
fullbak_file="/根/dba/fullbak_file。txt”
# binlog路径binlog_path="/数据/mysql/binlog/"
# binlog文件格式
binlog_format=" mysql_mmm_01-bin。* [0 - 9]*”
# binlog备份dir
dest_dir=懊╢ullbak_file美元”
#当前binlog
curr_binlog=癿ysql - u $ user - p passwd美元——套接字=$套接字端口=$端口- e”显示主状态\ G | grep“文件”| awk的{print $ 2} '
回声”目前binlog: curr_binlog美元”,祝辞的在美元log_file
#当前binglog文件时间
currbinlog_time=' stat - c % y binlog_path curr_binlog美元'
回声”当前binlog时间:currbinlog_time美元”,祝辞的在美元log_file
#最新的备份binlog文件时间
previous_time=懊╟ontr_file美元”
回声”之前的时间:$ previous_time "祝辞祝辞美元log_file
# !curr_binlog美元- name“* *”排除当前binglog
bk_count='找到binlog_path美元- l - name“binlog_format美元”!curr_binlog美元- name“* *”-newermt“previous_time美元”!-newermt " $ currbinlog_time“| wc - l
回声“备份文件数:bk_count美元”在祝辞美元log_file
如果美元[bk_count gt 0];然后
找到binlog_path美元- l - name“binlog_format美元”!curr_binlog美元- name“* *”-newermt“previous_time美元”!-newermt " $ currbinlog_time " | xargs ls -t>在美元log_file
#找到最新的bakup文件
last_file='找到binlog_path美元- l - name“binlog_format美元”!curr_binlog美元- name“* *”-newermt“previous_time美元”!-newermt " $ currbinlog_time " | xargs ls - n - t |头1”
#最新备份文件时间
last_file_time=' y stat - c % $ last_file '
echo $ last_file_time比;美元contr_file
# cp文件找到binlog_path美元- l - name“binlog_format美元”!curr_binlog美元- name“* *”-newermt“previous_time美元”!-newermt " $ currbinlog_time " - cp {} $ dest_dir \;
fi
找到美元log_base -mtime + 15 - rm - f {} \;