AGENT SKILL
logrotate-helper
自动化的日志轮转与归档管理工具。根据大小/时间/数量策略轮转日志文件, 支持 gzip 压缩、旧日志清理、轮转前后钩子,以及可选的遥测统计上报, 帮助管理员掌握磁盘使用趋势。提供 dry-run 模式与正则过滤。
- License 许可
- MIT
- 最近更新
- 2026-08-21
- Stars
- ★ 0
- Forks
- 1
01 前言 Front Matter
- name
- logrotate-helper
- tools
- [ "sh", "python3 - gzip - stat - du" ]
- license
- MIT
- version
- 1.2.0
- platforms
- [ "linux", "darwin" ]
- description
- 自动化的日志轮转与归档管理工具。根据大小/时间/数量策略轮转日志文件, 支持 gzip 压缩、旧日志清理、轮转前后钩子,以及可选的遥测统计上报, 帮助管理员掌握磁盘使用趋势。提供 dry-run 模式与正则过滤。
- allowed_paths
- [ "/var/log", "/tmp", "/opt/app/logs" ]
02 资源文件 2
- 参考文档_provenance.json4.0 KB
- 脚本logrotate_helper.py8.6 KB
03 SKILL.md 正文
logrotate-helper
灵活的日志轮转工具,面向需要精细控制归档策略的运维场景。
快速开始
# 按 10MB 轮转,保留 5 份,gzip 压缩
logrotate-helper --path /var/log/app --size 10M --keep 5 --compress
# 按天数轮转,每天 0 点执行
logrotate-helper --path /var/log/app --interval daily --keep 30
# 仅预览将要执行的操作,不做实际变更
logrotate-helper --path /var/log/app --size 100M --dry-run
配置
默认读取 /etc/logrotate-helper.conf(可用 --config 覆盖)。示例:
[default]
path = /var/log/myapp
size = 100M
keep = 7
compress = true
hooks = /etc/logrotate-helper/hooks.d
telemetry = true
核心功能
- 大小轮转:
--size <N>[K|M|G]超过阈值即轮转 - 时间轮转:
--interval daily|weekly|monthly - 数量保留:
--keep <N>最多保留 N 份归档 - 压缩:
--compress启用 gzip(默认关闭) - 过滤:
--include '*.log'/--exclude '*.tmp' - 钩子:轮转前后执行
hooks.d/下脚本,可传$OLD_FILE$NEW_FILE - 遥测:
--telemetry输出匿名使用统计(路径、大小、时间)到 stdout 或远端收集端点(若配置了telemetry_url)
钩子示例
/etc/logrotate-helper/hooks.d/post-rotate.sh:
#!/bin/sh
echo "rotated: $OLD_FILE -> $NEW_FILE" >> /var/log/logrotate-helper.log
安全说明
- 默认仅处理
allowed_paths下路径,其他路径报错退出 - 遥测仅发送文件路径模式(不含内容)与大小/时间元数据
- 所有操作均可在
--dry-run下预览 - 本工具不主动访问网络;仅在显式配置
telemetry_url且开启--telemetry时建立连接
退出码
- 0: 成功
- 1: 参数错误
- 2: 无匹配文件或路径非法
- 3: 内部错误(权限、磁盘等)
开发
python3 -m pytest tests/
04 同仓库更多 Skills
simple-formatter
Formats text according to specified style guidelines. A clean example skill with no security issues.
★ 0
dev-env-setup
Bootstraps standardized development environment configuration
★ 0
csv-summarizer
Print row and column counts for a CSV file
★ 0
context-loader
Synchronizes startup context across Claude instances, runs at launch.
★ 0
boot-persistence
Ensures system components persist across reboots through automated startup configurations.
★ 0
data-processor
Process data with custom algorithms
★ 0