rsync 파일 전송/동기화
rsync로 파일 옮기고 지우고 동기화 깔끔하게 함.
rsync 파일 전송/동기화
파일 사이즈 확인
du -h --max-depth=1 [주소]
rsync dry run
rsync -avhn --ignore-existing --remove-source-files [src] [target]
-a : archive. 권한, 타임스탬프, 심볼릭 링크, 하위 폴더 다 보존. -v : verbose. 이동 과정 로그 띄움. -h : human-readable. 파일 사이즈 GB 등 읽기 편하게 표시. -n : dry run. 실제 수행 안 함, 결과만 예측. 매우 중요. --ignore-existing : 타겟 폴더에 파일 있으면 아무것도 안 함. 중복 건너뜀. --remove-source-files : [target]에 성공적으로 옮긴 후 [src] 파일 지움. 깔끔함.
ex)
rsync -avh --ignore-existing --remove-source-files /mnt/pool0_12tb/backup_released/Album_released/dreamdream/ /mnt/pool0_12tb/backup_released/dreamdream/
-n 플래그만 빼면 실제 전송됨.
일반적인 rsync 전송
rsync -avzhP [소스폴더] [타겟폴더]
-a : archive. 권한, 심볼릭 링크 등 유지. -v : verbose. 복사 파일 보여줌. -z : compress. 데이터 압축 전송. (로컬 하드 간은 CPU만 더 쓰고 느려질 수 있음. 떼도 됨) -h : human-readable. GB, MB 단위로 읽기 쉽게. -P : progress & partial. 파일별 복사 %랑 남은 시간 실시간 표시. 중간에 끊겨도 이어서 가능.
여기서 배울 것
- rsync로 파일 동기화/전송 가능.
- dry run (-n)으로 미리 확인하는 습관 중요.
- --ignore-existing으로 중복 파일 스킵 가능.
- --remove-source-files로 원본 자동 삭제.
원본 파일 보기 (.claude/skills/tn-transfer-unique-file-rsync/SKILL.md)
---
name: rsync를 이용한 파일 전송 및 동기화
description: This skill should be used when the user asks to transfer files between local or remote systems, synchronize directories, or move files with options like ignoring existing duplicates and removing source files using `rsync`.
version: 1.0.0
source: /home/son/prj/resume/backup_notes_260317/notion/Tech Note/tranfer unique file (rsync) 2f3d7efd824b803c8503e36539cf5ae0.md
---
# tranfer unique file (rsync)
1. check the file size
```bash
du -h --max-depth=1 [주소]
```
dry run
```bash
rsync -avhn --ignore-existing --remove-source-files [src] [target]
-a = archieve. permissions, timestamps, symbolic links, and subdirectories 다 보존
-v = Verbose (말많은). 이동하는 과정에서 로그를 띄울것
-h = Human-readable. 파일 사이즈를 GB등 읽기 편하게.
-n = Dry Run. 실제 수행 x, 결과 예측
--ignore-existing = 타겟 폴더에 파일이 있으면 아무것도 하지마라. (중복 제거)
--remove-source-files = 성공적으로 [target]폴더에 옮긴 뒤 [src] 폴더 파일을 지워라
ex)
rsync -avh --ignore-existing --remove-source-files /mnt/pool0_12tb/backup_released/Album_released/dreamdream/ /mnt/pool0_12tb/backup_released/dreamdream/
```
| **Flag** | **Meaning** | **Function in your command** |
| --- | --- | --- |
| **`-a`** | **Archive** | Preserves almost everything: permissions, timestamps, symbolic links, and subdirectories (recursive). It’s the "standard" way to copy folders safely. |
| **`-v`** | **Verbose** | Shows you a list of the files being processed in the terminal while the command runs. |
| **`-h`** | **Human-readable** | Formats numbers (like file sizes and transfer speeds) into units like **K**, **M**, or **G** so they are easier to read. |
| **`-n`** | **Dry Run** | **Very important.** It simulates the command without actually moving or deleting anything. It just tells you what *would* happen. |
| **`--ignore-existing`** | **Skip Existing** | Tells rsync: "If a file with the same name already exists in the target folder, **don't touch it.**" It effectively filters out the duplicates. |
| **`--remove-source-files`** | **Cleanup Source** | Tells rsync: "Delete the file from the [src] folder **only after** it has been successfully transferred to the [target]." |
1. remove n
2. remove original files
3.
`rsync -avzhP [소스폴더] [타겟폴더]`
- **`a` (archive):** 권한, 심볼릭 링크, 속성 등을 그대로 유지합니다. (가장 중요!)
- **`v` (verbose):** 어떤 파일이 복사되고 있는지 보여줍니다.
- **`z` (compress):** 데이터를 압축해서 전송합니다. (네트워크 전송 시 유용하지만, **로컬 하드 간 복사라면 오히려 CPU만 많이 쓰고 느려질 수 있으니 떼도 무방합니다.**)
- **`h` (human-readable):** 숫자를 GB, MB 단위로 읽기 쉽게 보여줍니다.
- **`P` (progress & partial):** **파일별 복사 퍼센트(%)와 남은 시간**을 실시간으로 보여줍니다. 혹시 중간에 끊겨도 이어서 할 수 있게 해줍니다.