cleanup rm safety
rm -rf 쓸 때 마운트 포인트 건드리면 바로 골로 감. 조심.
rm -rf 실수 사례:
rm -rf /mnt/[마운트_경로]
QA 테스트 파일 지우려다 마운트된 디스크 통째로 날려먹음. 234G 순삭됨. extundelete 써봤는데 복구 안 됨. wtf...
Safety rules:
- Cleanup 범위 제한
rm -rf /mnt/[디스크]/[앱_전용_서브디렉토리]/* -
절대
/mnt/[디스크]자체를 타겟으로 잡지 말 것. 무조건 앱 전용 폴더 안으로 scope 좁혀야 함. -
2>/dev/null 쓰지 말기
rm -rf [경로] 2>/dev/null -
에러 숨기면 'device busy' 같은 경고 신호도 못 봄. 지저분하게 에러 숨기지 말 것.
-
사고 터졌을 때
- 즉시 쓰기 중단하고 unmount부터 할 것. 그 다음 복구 시도.
여기서 배울 것
- rm -rf는 마운트 포인트 루트에 쓰면 바로 데이터 증발함
- 에러 메시지 숨기는 2>/dev/null은 파괴적인 명령어에 쓰지 말 것
- cleanup 할 때는 무조건 앱 전용 하위 디렉토리만 타겟팅
원본 파일 보기 (.claude/projects/-home-son-prj-qr-generator/memory/cleanup-rm-safety.md)
---
name: cleanup-rm-safety
description: "Hard rule — never let a cleanup rm target a mount point or its root; scope to the app's own subdir"
metadata:
node_type: memory
type: feedback
originSessionId: 9451119c-52e0-45a8-9fd9-8f7724e23508
---
While cleaning QA test uploads I ran `rm -rf /mnt/4tb` inside a cleanup line and **wiped 234G of the user's data** on the freshly-mounted 4TB disk (rm recursed into the live mount). Name/structure recovery (extundelete) failed; user had a backup so it was survivable — but it was a serious, avoidable mistake.
**Why:** `rm -rf` in a throwaway "cleanup" command is the highest-risk thing in a shell line; a stray mount-point path destroys real data instantly and silently (errors were even hidden by `2>/dev/null`).
**How to apply:**
- Cleanup deletes must target the app's OWN data subdir explicitly (e.g. `/mnt/3tb/qr-generator-files/*`), NEVER a `/mnt/<disk>` mount root.
- Re-read every `rm -rf` path before running; treat any `/mnt/*` top-level path as forbidden.
- Never add `2>/dev/null` to a destructive command — you lose the "device busy"/error signal that would warn you.
- On data loss: stop writes immediately (unmount), then recover. See [[qr-generator-deploy]].