脚本统计空间被谁占用了#
#!/bin/bash
# 指定要检查的目录
target_directory="/"
# 指定要显示的文件和目录数量
num_files=10
num_directories=10
# 打印磁盘空间使用情况
df -h
# 打印占用空间最大的目录
echo "Top $num_directories Directories:"
du -ah $target_directory | sort -rh | head -n $num_directories
# 打印占用空间最大的文件
echo "Top $num_files Files:"
find $target_directory -type f -exec du -Sh {} + | sort -rh | head -n $num_files
mysql数据清理#
mysql数据占用空间较大#
170G /data
140G /data/mysql-data
3.2G /data/mysql-data/VM-100-15-centos.err
1.1G /data/mysql-data/VM-100-15-centos-bin.000112
1.1G /data/mysql-data/VM-100-15-centos-bin.000111
1.1G /data/mysql-data/VM-100-15-centos-bin.000110
1.1G /data/mysql-data/VM-100-15-centos-bin.000109
1.1G /data/mysql-data/VM-100-15-centos-bin.000108
... 这些都是mysql的二进制文件
修改配置文件 my.cnf或
my.ini binlog过期时间#
log_bin = /path/to/binlog
expire_logs_days = N
mysql客户端手工删除二进制文件#
PURGE BINARY LOGS TO 'VM-100-15-centos-bin.000110';
重启mysql#
sudo service mysql restart