当前位置:网站首页>mysql审计日志归档
mysql审计日志归档
2022-07-05 04:48:00 【huryer】
mysql审计日志归档
1、开启审计日志
# 启动审计,在mysql中执行命令:
set global general_log=on;
set global log_timestamps=SYSTEM;
set global general_log_file='db-1.log';
2、审计日志归档
创建归档备份目录
# 创建归档备份目录
mkdir -p /data/backup/audit
cd /data/backup/audit
创建审计日志归档脚本
vim mysql_aud_backup.sh
脚本内容如下:
#!/bin/bash
# mysql审计日志归档脚本
# 保留最近30天审计日志
# 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
# 设置日志文件路径
aud_folder=/data/mysql/data
backup_folder=/data/backup/audit
# 指定审计日志文件名
fn=db-1.log
dt=$(date +%Y%m%d)
# 切换到审计日志路径
cd $aud_folder
# 归档审计日志
mv $fn $fn.$dt
mysqladmin flush-logs -u root -p'my_sql_pwd'
mv $fn.$dt $backup_folder/
# 保留30天内的审计日志
find $backup_folder/ -mtime +30 -name "$fn.*" |xargs rm -f
添加可执行权限
# 添加可执行权限
chmod +x mysql_aud_backup.sh
3、添加计划任务
# 添加计划任务
crontab -e
0 1 * * * nohup sh /data/backup/audit/mysql_aud_backup.sh &
边栏推荐
- Understand encodefloatrgba and decodefloatrgba
- 2021 Higher Education Club Cup mathematical modeling national tournament ABCD problem - problem solving ideas
- Neural networks and deep learning Chapter 6: Circular neural networks reading questions
- JMeter -- distributed pressure measurement
- Reading and visualization of DICOM, MHD and raw files in medical imaging
- 线上故障突突突?如何紧急诊断、排查与恢复
- AutoCAD - workspace settings
- SQL set operation
- QT Bluetooth: a class for searching Bluetooth devices -- qbluetooth devicediscoveryagent
- Mode in BST (binary tree & Notes on question brushing)
猜你喜欢
The remainder operation is a hash function
An article takes you to thoroughly understand descriptors
AutoCAD - Center zoom
Raki's notes on reading paper: code and named entity recognition in stackoverflow
Live broadcast preview | container service ack elasticity prediction best practice
Observable time series data downsampling practice in Prometheus
自动语音识别(ASR)研究综述
Is $20billion a little less? Cisco is interested in Splunk?
CUDA Programming atomic operation atomicadd reports error err:msb3721, return code 1
Introduction to JVM principle and process
随机推荐
[groovy] closure (Introduction to closure class closure | closure parametertypes and maximumnumberofparameters member usage)
包 类 包的作用域
#775 Div.1 B. Integral Array 数学
Solutions and answers for the 2021 Shenzhen cup
Looking at Chinese science and technology from the Winter Olympics: what is the mystery of the high-speed camera that the whole people thank?
What are the building energy-saving software
2021 higher education social cup mathematical modeling national tournament ABCD questions - problem solving ideas - Mathematical Modeling
Detailed introduction of OSPF header message
CSDN正文自动生成目录
You Li takes you to talk about C language 7 (define constants and macros)
Rk3399 platform development series explanation (network debugging) 7.29 summary of network performance tools
Function template
数论函数及其求和 待更新
揭秘技术 Leader 必备的七大清奇脑回路
[crampon programming] lintcode decoding Encyclopedia - 872 termination process
CUDA Programming atomic operation atomicadd reports error err:msb3721, return code 1
Label exchange experiment
Reading and visualization of DICOM, MHD and raw files in medical imaging
[goweb development] Introduction to authentication modes based on cookies, sessions and JWT tokens
Is there a sudden failure on the line? How to make emergency diagnosis, troubleshooting and recovery