Disk Cleanup
Automated disk space recovery for OpenClaw deployments. Covers 12 cleanup categories that OpenClaw does not handle natively (as of 2026.3.13).
What OpenClaw Already Handles (skip these)
- - Session store:
session.maintenance config (pruneAfter, maxEntries, rotateBytes) - Sandbox containers:
sandbox.prune config (idleHours, maxAgeDays) - Context pruning:
contextPruning config (cache-ttl mode)
What This Skill Handles (the gaps)
| # | Category | Typical Growth | Trigger |
|---|
| 1 | Memory SQLite .tmp-* orphans | Hundreds of MB from failed reindex | Always |
| 2 |
Memory SQLite VACUUM | Fragmentation after heavy use |
--aggressive |
| 3 | Docker images/volumes/build cache | GB from sandbox rebuilds | Always |
| 4 | Gateway logs (
/tmp/openclaw/*.log) | Grows daily | >3 days old |
| 5 |
/tmp OpenClaw temp files | Patrol/board/cron artifacts | >24h old |
| 6 | Workspace
.prebind.* backups | Hundreds of MB per backup | >7 days old |
| 7 | Delivery queue old entries | Grows with message volume | >7 days old |
| 8 | systemd journal | GB on default VPS configs | >500MB |
| 9 | npm/yarn/pnpm/bun/prisma/node-gyp cache | GB from skill/plugin installs | >100MB |
| 10 | Rotated syslogs + btmp | SSH brute-force logs on public VPS | Always |
| 11 | Git workspace
.git | Auto-commit growth (board-move etc.) | >200MB |
| 12 | QMD/migration artifacts | Stale after backend switch | Auto-detected |
Quick Start
Run directly:
CODEBLOCK0
Schedule as Cron Job
Weekly Sunday 04:00 CET (recommended):
CODEBLOCK1
Or integrate into an existing infra-health-check script by adding a disk usage threshold trigger:
CODEBLOCK2
Environment Variables
| Variable | Default | Description |
|---|
| INLINECODE9 | INLINECODE10 | OpenClaw state directory |
| INLINECODE11 |
$(pwd) | Agent workspace root |
Exit Codes
- -
0 — Success (cleaned or nothing to clean) - INLINECODE14 — Error during cleanup
Output Format
Last line is machine-parseable:
CODEBLOCK3
Safety
- -
--dry-run previews all actions without deleting - SQLite VACUUM only on
--aggressive and only when fragmentation ≥5% - Docker prune only removes dangling (untagged) images; named images are safe
- btmp is truncated (not deleted) — system expects the file to exist
- Journal vacuum installs a persistent 500MB limit to prevent regrowth
- Git gc uses
--auto by default; --aggressive only with flag
磁盘清理
为OpenClaw部署提供自动化磁盘空间回收。涵盖OpenClaw原生未处理的12个清理类别(截至2026.3.13)。
OpenClaw已处理项(跳过这些)
- - 会话存储:session.maintenance配置(pruneAfter、maxEntries、rotateBytes)
- 沙箱容器:sandbox.prune配置(idleHours、maxAgeDays)
- 上下文修剪:contextPruning配置(cache-ttl模式)
本技能处理项(空白领域)
| # | 类别 | 典型增长量 | 触发条件 |
|---|
| 1 | 内存SQLite .tmp-* 孤儿文件 | 因重建索引失败产生数百MB | 始终 |
| 2 |
内存SQLite VACUUM | 重度使用后产生碎片 | --aggressive |
| 3 | Docker镜像/卷/构建缓存 | 沙箱重建产生GB级数据 | 始终 |
| 4 | 网关日志(/tmp/openclaw/*.log) | 每日增长 | 超过3天 |
| 5 | /tmp OpenClaw临时文件 | 巡逻/面板/cron产物 | 超过24小时 |
| 6 | 工作区 .prebind.* 备份 | 每次备份数百MB | 超过7天 |
| 7 | 投递队列旧条目 | 随消息量增长 | 超过7天 |
| 8 | systemd日志 | 默认VPS配置下产生GB级数据 | 超过500MB |
| 9 | npm/yarn/pnpm/bun/prisma/node-gyp缓存 | 技能/插件安装产生GB级数据 | 超过100MB |
| 10 | 轮转系统日志+btmp | 公共VPS上的SSH暴力破解日志 | 始终 |
| 11 | Git工作区 .git | 自动提交增长(面板移动等) | 超过200MB |
| 12 | QMD/迁移产物 | 后端切换后过时 | 自动检测 |
快速开始
直接运行:
bash
预览将要清理的内容(安全,不会删除)
bash scripts/disk-cleanup.sh --dry-run
常规清理
bash scripts/disk-cleanup.sh
深度清理:包括SQLite VACUUM + 激进git gc
bash scripts/disk-cleanup.sh --aggressive
Cron模式:仅输出摘要行
bash scripts/disk-cleanup.sh --quiet
设置为Cron任务
每周日04:00 CET(推荐):
使用cron工具:
schedule: { kind: cron, expr: 0 3 0, tz: Europe/Luxembourg }
payload: { kind: agentTurn, message: 运行磁盘清理:bash scripts/disk-cleanup.sh --aggressive --quiet。报告结果。 }
sessionTarget: isolated
或集成到现有的基础设施健康检查脚本中,添加磁盘使用阈值触发:
bash
DISK_PCT=$(df / --output=pcent | tail -1 | tr -d %)
if [ $DISK_PCT -ge 85 ]; then
bash /path/to/disk-cleanup.sh --quiet
fi
if [ $DISK_PCT -ge 90 ]; then
bash /path/to/disk-cleanup.sh --aggressive --quiet
fi
环境变量
| 变量 | 默认值 | 描述 |
|---|
| OPENCLAWHOME | ~/.openclaw | OpenClaw状态目录 |
| OPENCLAWWORKSPACE |
$(pwd) | 代理工作区根目录 |
退出码
- - 0 — 成功(已清理或无需清理)
- 1 — 清理过程中出错
输出格式
最后一行可被机器解析:
CLEAN|0|0B|44% # 未清理任何内容
CLEANED|5|1.2GB|67% # 5个操作,释放1.2GB,当前使用率67%
安全性
- - --dry-run 预览所有操作而不删除
- SQLite VACUUM仅在 --aggressive 且碎片率≥5%时执行
- Docker清理仅移除悬空(未标记)镜像;命名镜像安全
- btmp被截断(而非删除)——系统期望该文件存在
- 日志清理会安装持久化的500MB限制以防止重新增长
- Git gc默认使用 --auto;--aggressive 仅在指定标志时使用