C.W.K.
Stream
Lesson 07 of 12 · published

Dry Run & --delete 안전

~12 min · dry-run, delete, safety, backup

Level 0Pinger
0 XP0/101 lessons0/12 achievements
0/150 XP to next level150 XP to go0% complete

--dry-run 은 협상 불가

-n(또는 --dry-run) 이 실행 없이 정확히 rsync 가 뭐 할지 보여줌. 종교적으로 사용 — 특히 destructive 한 거. 비용은 명령 하나 더; 상승은 절대 작업 실수로 삭제 안 함.

--delete 가 목적지를 mirror 로

--delete 가 출처에 없는 파일 목적지에서 제거. Sync 를 진정한 mirror 작업으로. 강력하고 위험 동등 — 잘못된 trailing slash 와 함께면 몇 초 안에 잘못된 디렉토리 wipe.

Backup-and-delete — --backup-dir

Delete 안전 원하면 --backup --backup-dir=/some/path 로 "삭제된" 파일을 제거 대신 backup 디렉토리로 이동. 실수에서 복구할 만큼 머물러. 날짜 sub 디렉토리와 짝지으면 가난뱅이 snapshot 시스템.

Code

Dry run, real, safe-delete·bash
# 1. Dry run first
rsync -avzn --delete source/ dest/
# Read the output. Are the files-to-delete actually correct?

# 2. Real run only after the dry run looks right
rsync -avz --delete source/ dest/

# Safer: stash deletions in a backup-dir instead of removing
rsync -avz --delete \
  --backup --backup-dir=/tmp/rsync-bak-$(date +%Y%m%d) \
  source/ dest/

External links

Exercise

버려도 되는 디렉토리 페어에 source/ 와 dest/ 의도적으로 셋업 — dest/ 에 source/ 에 없는 파일 하나. rsync -avzn --delete source/ dest/ 돌려서 rsync 가 삭제하겠다는 파일 메모. 이제 --backup --backup-dir=/tmp/bak 로 — 파일이 사라지는 대신 /tmp/bak 으로 이동. 안전 패턴 내재화.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.