MySQL 数据库日志切割脚本
出处:?http://netkiller.github.io/?
?
#!/bin/bashUSER=backupPASS=SaJePoM6BAPOmOFOd7Xo3e1A52vEPELOGDIR="/tmp/backup"DATADIR="/var/lib/mysql"LOG=mysql.logLOG_ERROR=mysql_error.logLOG_SLOW_QUERIES=slow.logSOCKET="/var/lib/mysql/mysql.sock"#Number of copiesCOPIES=30SHARDING=$(date -d "yesterday" +"%Y-%m-%d") mkdir -p ${LOGDIR}/${SHARDING} while read logfile agedo mv ${DATADIR}/$logfile ${LOGDIR}/${SHARDING}done << EOF${LOG}${LOG_ERROR}${LOG_SLOW_QUERIES}EOF mysqladmin -u${USER} -p${PASS} --socket=${SOCKET} flush-logs find $LOGDIR -type f -ctime +$COPIES -delete
?
?https://gist.github.com/netkiller/7904307