rsync trailing-slash + --delete 함정
rsync --delete 쓸 때 trailing slash 조심해야 함. 파일 다 날아감.
rsync -az --delete /tmp/thesis_v2/papergen/ 192.168.1.116:~/prj/thesis/
이거 위험한 명령어였음.
source에 trailing slash 있으면 papergen/ 내용이 dest ~/prj/thesis/로 바로 복사됨.
--delete 때문에 dest에 없는 .venv, state/, output/, requirements.txt 다 날아감.
복구 10분 넘게 걸림 (re-pip-install + re-publish). wtf.
왜 이랬나:
여러 개 dest를 한 커맨드로 묶음.
source trailing slash랑 --delete 조합, dest가 독립적이지 않으면 엉뚱한 파일들 다 날리는 지름길.
앞으로 이렇게:
* project root로 sync할 때 --delete는 dest가 source 전용일 때만 사용. papergen/ → papergen/처럼 쓸 것. project root에 바로 덮어쓰기 금지.
* source/dest 디렉토리 이름 맞추는 거 선호: rsync -az /tmp/thesis_v2/papergen/ host:~/prj/thesis/papergen/
* --delete 없어도 path 정확히 하는 게 중요.
* 여러 파일 push할 땐 각 subtree 별도 rsync, 아니면 --filter로 정확히 지정. 한 커맨드에 source path 여러 개 붙이지 마.
* --delete 쓰기 전엔 꼭 --dry-run 먼저 해서 뭐 날아갈지 확인.
여기서 배울 것
- project root로 sync할 때 `--delete`는 dest가 source 전용일 때만 사용.
- source/dest 디렉토리 이름 맞추는 거 선호.
- 여러 파일 push할 땐 각 subtree 별도 rsync or `--filter` 사용.
- `--delete` 쓰기 전엔 꼭 `--dry-run` 먼저.
원본 파일 보기 (.claude/projects/-home-son-prj-thesis/memory/rsync_lesson.md)
---
name: rsync trailing-slash + --delete pitfall
description: One mistake destroyed son-pro6000's .venv and state - record so future rsyncs are surgical
type: feedback
originSessionId: a80e3f6f-bf8c-4ef5-93e8-e5c44239beaa
---
`rsync -az --delete /tmp/thesis_v2/papergen/ 192.168.1.116:~/prj/thesis/` is a destructive command. Source has trailing slash → contents of `papergen/` get copied directly into `~/prj/thesis/`. `--delete` then removes everything in destination that isn't in source — including `.venv`, `state/`, `output/`, `requirements.txt`. Recovering took 10+ minutes (re-pip-install + re-publish).
**Why:** I bundled the dest-of-many-things into one command. The trailing slash on source plus `--delete` on a non-isolated dest is a recipe for wiping unrelated files.
**How to apply:**
- When syncing into a project root, never use `--delete` unless the destination is dedicated to the source set. Use `--delete` only with `papergen/` → `papergen/`, never with the project root.
- Prefer matching source and destination directory names: `rsync -az /tmp/thesis_v2/papergen/ host:~/prj/thesis/papergen/`. Even without `--delete`, getting paths right matters.
- For multi-file pushes, `rsync` each subtree separately, or use a single `rsync -az --filter` rule that names exactly what should land. Don't just append a second source path to the same command.
- Before any `--delete`, do a `--dry-run` once to see what will disappear.