2026-07-23 08:45:07 +08:00
2026-07-23 14:37:30 +08:00
2026-07-15 13:58:32 +08:00
2026-07-15 13:58:32 +08:00
2026-07-23 14:37:30 +08:00

cleanup-smartcam-data 部署说明

cleanup-smartcam-data 自动清理策略

文件结构

cleanup-smartcam-data/
├── README.md
├── assets/
│   ├── cleanup-smartcam-data-flow.svg(旧版源文件)
│   └── cleanup-smartcam-data-flow.png(当前流程图)
├── bin/
│   └── cleanup-smartcam-data
├── systemd/
│   ├── cleanup-smartcam-data.service
│   ├── cleanup-smartcam-data-resume.timer
│   └── cleanup-smartcam-data.timer
└── scripts/
    ├── install.sh
    └── uninstall.sh

RK3588 安装位置

项目文件 设备安装位置
bin/cleanup-smartcam-data /usr/local/sbin/cleanup-smartcam-data
systemd/cleanup-smartcam-data.service /etc/systemd/system/cleanup-smartcam-data.service
systemd/cleanup-smartcam-data.timer /etc/systemd/system/cleanup-smartcam-data.timer
systemd/cleanup-smartcam-data-resume.timer /etc/systemd/system/cleanup-smartcam-data-resume.timer

运行状态目录由程序自动创建:

/var/lib/cleanup-smartcam-data/
/run/cleanup-smartcam-data.lock

环境要求

  • smart-cam 容器名:smart-cam
  • 数据目录:/userdata/data
  • 容器内成功记录:/smart-cam/kafka_sender/processed_files.log
  • 采集进程命令包含:build/bin/smart_camera
  • 宿主机使用 Docker 和 systemd

安装

将整个目录复制到目标设备,例如:

/home/zhangw/cleanup-smartcam-data

执行:

cd /home/zhangw/cleanup-smartcam-data
sudo ./scripts/install.sh

安装脚本会:

  1. 校验清理脚本语法;
  2. 安装程序和 systemd unit;
  3. 启用 cleanup-smartcam-data.timer;
  4. 删除旧名称 userdata-video-cleanup 的安装文件;
  5. 不停止或重启 smart-cam Docker。

清理规则

  • 开机2分钟后首次检查;
  • 之后每60分钟检查一次;
  • 每次定时检查都会安全清理已确认上传成功的数据,不以空闲空间阈值作为清理条件;
  • 只清理 processed_files.log 中确认成功、且超过60分钟的数据;
  • 同时删除同一任务的:
/userdata/data/videos/<base>_annotated.mp4
/userdata/data/videos_raw/<base>_raw.mp4
/userdata/data/annotations/<base>.xml
  • 超过60分钟的0字节 raw,如果未被进程占用,也会按上述三件套删除;
  • 对<base>_raw.mp4.partN.mp4录制残留执行整组安全检查:
    • 同一base的所有part都必须超过60分钟、全部为0字节且均未被进程打开;
    • 如果正式<base>_raw.mp4已经存在,只删除符合条件的残留part,保留正常三件套;
    • 如果正式raw不存在,删除全部残留part及对应的annotated视频和XML;
    • 任一part仍较新、非0字节或正在使用时,整组跳过;
  • 空闲低于3GiB时暂停整个 smart_camera 进程(持续检测、录像和识别一起暂停),Producer继续上传,并输出 CRITICAL 告警;
  • 暂停期间每2分钟检查一次;
  • 清理使空闲恢复到5GiB后自动恢复 smart_camera;程序重新持续检测,达到鸟类确认门控后再录像和识别,并停止2分钟快速检查;
  • 无法读取成功记录时不删除数据。

验证

sudo bash -n /usr/local/sbin/cleanup-smartcam-data

systemctl status cleanup-smartcam-data.timer
systemctl list-timers --all | grep cleanup-smartcam-data

sudo systemctl start cleanup-smartcam-data.service
systemctl status cleanup-smartcam-data.service

journalctl -u cleanup-smartcam-data.service -n 100 --no-pager

确认成功记录可读:

docker exec smart-cam \
  test -r /smart-cam/kafka_sender/processed_files.log

确认 Docker 未重启:

docker inspect smart-cam --format \
  'running={{.State.Running}} restart={{.RestartCount}} started={{.State.StartedAt}}'

查看日志

journalctl -u cleanup-smartcam-data.service -f
docker logs -f -t --tail 200 smart-cam

日志标识:

[DISK_GUARD][INFO]
[DISK_GUARD][WARNING]
[DISK_GUARD][CRITICAL]
[DISK_GUARD][RECOVERED]

升级

在目标设备进入新版目录后重新执行:

cd /home/zhangw/cleanup-smartcam-data
sudo ./scripts/install.sh

卸载

cd /home/zhangw/cleanup-smartcam-data
sudo ./scripts/uninstall.sh

卸载后检查采集是否处于暂停状态,再决定是否删除:

/var/lib/cleanup-smartcam-data/
S
Description
智能摄像头端侧自动清理数据
Readme
2.9 MiB
0 Stars 1 Watchers 0 Forks
Languages
Shell 100%