查看磁盘大小
df -h
看挂载点是/的项目
看内存使用大小
bash
free -h
查看cpu的大小和负载
bash
top -c
查看库大小
bash
mysql -u root -p
select table_schema as '数据库', sum(table_rows) as '记录数',sum(truncate(data_length/1024/1024, 2)) as '数据容量(MB)', sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)' from information_schema.tables where table_schema='zabbix';
查看表大小,删除视情况而定
bash
use zaabix;
select table_schema as '数据库', table_name as '表名', table_rows as '记录数',truncate(data_length/1024/1024, 2) as '数据容量(MB)', truncate(index_length/1024/1024, 2) as '索引容量(MB)' from information_schema.tables order by data_length desc, index_length desc;
数据库备份
下面是一个创建shell脚本,目录,定时任务,可自行修改
powershell
mkdir /root/mysqldump
vim /root/mysqldump/mysqldump.sh
将下面的脚本复制进去
powershell
#!/bin/bash
# 设置数据库连接信息
DB_USER="root"
DB_PASSWORD="zabbix"
DB_NAME="zabbix"
# 设置备份目录和文件名格式
BACKUP_DIR="/root/mysqldump"
DATE=$(date +%Y%m%d)
FILENAME="$DB_NAME-$DATE.sql"
# 使用mysqldump备份数据库
mysqldump -u $DB_USER -p$DB_PASSWORD $DB_NAME > "$BACKUP_DIR/$FILENAME"
# 删除15天前的备份文件
find "$BACKUP_DIR" -type f -name "*.sql" -mtime +15 -exec rm {} \;
powershell
crontab -e
0 1 * * * /root/mysqldump/mysqldump.sh >> /root/mysqldump/logfile.log 2>&1
#上面的意思是每天凌晨1点执行
一些网站
https://tool.lu/timestamp/ #查看时间戳
https://tool.lu/crontab/ #定时任务编辑器