当前位置:网站首页>MySQL audit log archiving

MySQL audit log archiving

2022-07-05 04:49:00 huryer

mysql Audit log archiving

1、 Open audit log

#  Start audit , stay mysql Middle execution command :
set global general_log=on;
set global log_timestamps=SYSTEM;
set global general_log_file='db-1.log';

2、 Audit log archiving

Create an archive backup directory

#  Create an archive backup directory 
mkdir -p /data/backup/audit
cd /data/backup/audit

Create audit log archive script

vim mysql_aud_backup.sh 

 The script is as follows :

#!/bin/bash
# mysql Audit log archive script 
#  Keep recent 30 Day audit log 
# crontab -l
# 0 1 * * * nohup sh /data/backup/audit/mysql_aud_backup.sh &

export PATH=.:$PATH:/usr/local/mysql-5.7.34-el7-x86_64/bin

#  Set log file path 
aud_folder=/data/mysql/data
backup_folder=/data/backup/audit

#  Specify the audit log file name 
fn=db-1.log
dt=$(date +%Y%m%d)

#  Switch to the audit log path 
cd $aud_folder

#  Archive audit logs 
mv $fn $fn.$dt
mysqladmin flush-logs -u root -p'my_sql_pwd'
mv $fn.$dt $backup_folder/
#  Retain 30 Audit log within days 
find $backup_folder/ -mtime +30 -name "$fn.*" |xargs rm -f

Add executable rights

#  Add executable rights 
chmod +x mysql_aud_backup.sh

3、 Add scheduled tasks

#  Add scheduled tasks 
crontab -e
0 1 * * * nohup sh /data/backup/audit/mysql_aud_backup.sh &

原网站

版权声明
本文为[huryer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050448258048.html