使用logrotate轮替MySQL的mysql-audit审计日志

/data/mysqldata/mysql-audit.json {
    prerotate
        # stop mysql audit
        if test -x /usr/local/mysql/bin/mysql && \
          /usr/local/mysql/bin/mysqladmin ping &>/dev/null
        then
          /usr/local/mysql/bin/mysql -e "SET GLOBAL audit_json_file=OFF;"
        fi
    endscript
        create 0600 mysql mysql
        notifempty
        daily
        rotate 5
        missingok
        compress
    postrotate
        # just if mysqld is really running and start mysql audit
        if test -x /usr/local/mysql/bin/mysqladmin && \
          /usr/local/mysql/bin/mysqladmin ping &>/dev/null
        then
          /usr/local/mysql/bin/mysqladmin flush-logs && \
          /usr/local/mysql/bin/mysql -e "SET GLOBAL audit_json_file=ON;"
        fi
    endscript
}

相关推荐