mysql备份清理脚本

mysql备份清理脚本

cat cleanUp_binlog.sh 
#!/bin/bash
#author:royoy
#date:20170608
#desc:clean up binlog before 3 days

#reserved time of binlog; value 2 is 3 days, 3 is 4 days ...
binlog_reserved_time="2"

#root dir of binlog files
binlog_root_dir="/data/backup/binlog/"

#log file of cleanUp script
log_file="${binlog_root_dir}cleanUp.log"

#sc binlog dir
sc_xtmgame_binlog="${binlog_root_dir}sc/xtmgame/"
sc_passport_binlog="${binlog_root_dir}sc/passport/"

#hc binlog dir
hc_xtmgame_binlog="${binlog_root_dir}hc/xtmgame/"
hc_passport_binlog="${binlog_root_dir}hc/passport/"

#99 binlog dir
c99_xtmgame_binlog="${binlog_root_dir}99c/xtmgame/"

#jy binlog dir
jy_xtmgame_binlog="${binlog_root_dir}jyc/xtmgame/"

#jx binlog dir
jx_xtmgame_binlog="${binlog_root_dir}jxc/xtmgame/"

#jjly binlog dir
jjly_xtmgame_binlog="${binlog_root_dir}jjly/xtmgame/"

###del binlog before $((binlog_reserved_time+1)) days###
for i in ${sc_xtmgame_binlog} ${sc_passport_binlog} ${hc_xtmgame_binlog} ${hc_passport_binlog} ${c99_xtmgame_binlog} ${jy_xtmgame_binlog} ${jx_xtmgame_binlog} ${jjly_xtmgame_binlog}
do
	find $i -mtime +"${binlog_reserved_time}" -type f -print |xargs -i ls -l {} |awk '{print $6,$7,$8,$9}' \
	|awk '{print "rm -f "$4" && echo \"$(date) start to delete "$1,$2,$3,$4"\" OK"}' |/bin/bash >>${log_file} 2>&1
done