--- name: coruna-lab-cleanup description: >- Clean up disk space on servers running the coruna-lab (Coruna Lab) Laravel project. Deletes scanned photos without mnemonic findings, prunes broken-image DB rows, clears DS scan result intermediates, purges old logs, truncates nginx logs, and removes stale backups. Use when the user reports disk full / low space on a coruna-lab server, or asks to clean up photos / DS results / process data / broken images (裂图) on a coruna-lab deployment. Trigger keywords: coruna-lab 磁盘清理, 清理相册, 清理照片, 清理 DS 结果, 清理过程数据, 裂图, disk full, prune photos, clean ds-results. --- # coruna-lab Disk Cleanup Clean up disk space on servers running the **coruna-lab** Laravel project. ## Project layout (reference) ``` /www/wwwroot/coruna-lab/ # project root (auto-detected or arg) ├── storage/app/private/c2/ │ ├── photos/ # original album photos (linked to photos table) │ ├── ds-results/ # DS scan intermediates (images already in photos/) │ ├── ds-chunks/ # temporary chunk-assembly files │ ├── inbox/ # incoming .bin payloads from devices │ ├── photo-previews/ # preview cache (regenerable) │ ├── plugin-sessions/ # plugin session data │ └── ds-notes/ # DS note data ├── public/log/ # app logs: xxbb/, ds/, transfer/, c2/ ├── artisan ``` ### Key DB tables | Table | Role | |-------|------| | `photos` | album photos, `scan_status`: 0=未扫 1=已扫空 2=疑似 3=确定 4=失败 | | `photo_reads` | read markers per photo | | `mnemonic_findings` | mnemonic phrases found in photos/notes (has `photo_id`) | **Safe to delete**: `scan_status=1` photos with NO `mnemonic_findings` row — scanned, nothing found. **Never delete**: `scan_status=0` (pending scan), `scan_status=2/3` (has mnemonic findings), `mnemonic_findings` rows. ## Cleanup steps The bundled `scripts/disk_cleanup.sh` runs all steps. Always **dry-run first**. ### Step 1: Run dry-run ```bash # SSH to the target server, then: bash /scripts/disk_cleanup.sh /www/wwwroot/coruna-lab ``` This prints what would be cleaned without deleting anything. Review the output. ### Step 2: Execute cleanup ```bash sudo bash /scripts/disk_cleanup.sh /www/wwwroot/coruna-lab --execute ``` ### What it does (9 steps) | # | Step | Default retention | Frees | |---|------|-------------------|-------| | 1 | Old app logs (`public/log/*.log`) | 7 days | varies | | 2 | scan_status=1 photos (no mnemonic) | all | largest — often 50-100G+ | | 3 | Broken-image DB rows (file missing) | all | fixes 裂图 | | 4 | Photo preview caches | all | ~15G typical | | 5 | DS results (`ds-results/`) | 1 day | often 40-80G | | 6 | DS chunks (`ds-chunks/`) | 1 day | often 20-35G | | 7 | Inbox (`inbox/`) | 3 days | varies | | 8 | Nginx logs (truncate >100M files) | — | often 15-20G | | 9 | Backups (`/www/backup/`) | all | varies | ### Tunable retention (env vars) ```bash LOG_RETENTION_DAYS=3 DS_RESULTS_RETENTION_DAYS=1 DS_CHUNK_RETENTION_DAYS=1 \ INBOX_RETENTION_DAYS=3 CLEAN_NGINX_LOGS=1 CLEAN_BACKUPS=1 \ bash /scripts/disk_cleanup.sh /www/wwwroot/coruna-lab --execute ``` ## Individual steps (if full pipeline not needed) ### Only clean scanned photos (step 2 standalone) ```bash # Copy the PHP script into the project, then run via Laravel bootstrap: cp /scripts/cleanup_scanned_photos.php /www/wwwroot/coruna-lab/ cd /www/wwwroot/coruna-lab php cleanup_scanned_photos.php # dry-run php cleanup_scanned_photos.php --execute # actually delete rm -f cleanup_scanned_photos.php # clean up after ``` ### Only prune broken images (step 3 standalone) ```bash cd /www/wwwroot/coruna-lab php artisan coruna:prune-missing-photo-files # dry-run php artisan coruna:prune-missing-photo-files --execute # delete rows ``` ### Only clean DS intermediates (steps 5-6 standalone) ```bash find /www/wwwroot/coruna-lab/storage/app/private/c2/ds-results/ -type f -mtime +1 -delete find /www/wwwroot/coruna-lab/storage/app/private/c2/ds-results/ -type d -empty -delete find /www/wwwroot/coruna-lab/storage/app/private/c2/ds-chunks/ -type f -mtime +1 -delete find /www/wwwroot/coruna-lab/storage/app/private/c2/ds-chunks/ -type d -empty -delete ``` ## Safety rules 1. **Always dry-run first** — review counts before `--execute`. 2. **Never delete `scan_status=0` or `scan_status=2/3` photos** — they are pending scan or contain mnemonic findings. 3. **Never delete `mnemonic_findings` rows** — these are the extracted mnemonic records. 4. DS results images are duplicates of `c2/photos/` — safe to delete after processing. 5. Photo previews are cache — regenerable, safe to clear. 6. Truncating nginx logs (not deleting) keeps the file handle open for the running nginx process. 7. Backups under `/www/backup/` are panel-level backups — confirm with user before deleting on production servers where backups are actively needed. ## Verification after cleanup ```bash df -h / du -sh /www/wwwroot/coruna-lab/storage/app/private/c2/*/ du -sh /www/wwwroot/coruna-lab/public/log/ ``` Check DB counts: ```bash cd /www/wwwroot/coruna-lab php artisan tinker --execute=" echo 'photos: '.DB::table('photos')->count().PHP_EOL; echo 'photo_reads: '.DB::table('photo_reads')->count().PHP_EOL; echo 'mnemonic_findings: '.DB::table('mnemonic_findings')->count().PHP_EOL; " ```