Apa itu Rsync?
Rsync (Remote Synchronization) adalah tool powerful untuk sinkronisasi file dan direktori antara lokasi berbeda, baik secara lokal maupun remote. Keunggulan utamanya adalah hanya mentransfer perubahan (delta transfer), membuatnya sangat efisien.
Keunggulan Rsync
Delta-transfer algorithm - Hanya transfer bagian yang berubah
Preserve permissions - Mempertahankan atribut file
Compression - Kompresi data selama transfer
Partial transfers - Dapat melanjutkan transfer yang terputus
Flexible - Bisa lokal dan remote
STRUKTUR DASAR
rsync [OPTIONS] SUMBER TUJUAN
OPTIONS PALING UMUM
1. Basic Options
# Archive mode (preserve semua atribut) rsync -a /source/ /dest/ # Verbose (lihat progress) rsync -av /source/ /dest/ # Recursive (untuk direktori) rsync -r /source/ /dest/ # Compression (untuk transfer remote) rsync -z /source/ user@host:/dest/
2. Kombinasi Umum
# Kombinasi paling sering digunakan rsync -avz /local/path/ user@remotehost:/remote/path/ # Archive + verbose + progress rsync -av --progress /source/ /dest/
OPTIONS DETAIL
A. Options Transfer & Sync
# Dry run (simulasi tanpa eksekusi) rsync -av --dry-run /source/ /dest/ # Delete files di destination yang tidak ada di source rsync -av --delete /source/ /dest/ # Exclude file/directory rsync -av --exclude='*.tmp' /source/ /dest/ rsync -av --exclude={'node_modules','.git'} /source/ /dest/ # Include hanya file tertentu rsync -av --include='*.txt' --exclude='*' /source/ /dest/ # Partial transfer (biarkan file partial) rsync -av --partial /source/ /dest/ # Continue transfer yang terputus rsync -av --append /source/ /dest/
B. Options Monitoring & Logging
# Progress bar rsync -av --progress /source/ /dest/ # Human readable format rsync -avh /source/ /dest/ # Stats setelah selesai rsync -av --stats /source/ /dest/ # Log ke file rsync -av --log-file=/path/to/logfile /source/ /dest/
C. Options Network & Remote
# Custom SSH port rsync -av -e "ssh -p 2222" /source/ user@host:/dest/ # Custom SSH options rsync -av -e "ssh -o ConnectTimeout=10" /source/ user@host:/dest/ # Bandwidth limit rsync -av --bwlimit=1000 /source/ /dest/ # 1000 KB/s # Timeout rsync -av --timeout=30 /source/ user@host:/dest/
D. Options File Handling
# Preserve permissions, timestamps, owner rsync -a /source/ /dest/ # Hanya update file yang lebih baru rsync -avu /source/ /dest/ # Backup file yang di-overwrite rsync -av --backup /source/ /dest/ # Backup dengan suffix rsync -av --backup --suffix=.bak /source/ /dest/ # Maximum file size rsync -av --max-size=100M /source/ /dest/ # Minimum file size rsync -av --min-size=1K /source/ /dest/
CONTOH PENGGUNAAN REAL-WORLD
1. Backup Website
rsync -avz --delete --progress \ /var/www/html/ user@backup-server:/backups/www/
2. Sync Database Backups
rsync -av --partial --progress \ /backups/db/ user@remote-server:/remote-backups/db/
3. Mirror Directory dengan Exclude
rsync -av --delete --exclude='.git' \ --exclude='node_modules' --exclude='*.log' \ /project/ user@production:/opt/project/
4. Transfer dengan Bandwidth Limit
rsync -avz --bwlimit=500 --progress \ /large-files/ user@remote:/storage/
5. Resume Transfer Besar
rsync -av --partial --progress --append \ /large-file.iso user@remote:/downloads/
PERBEDAAN TRAILING SLASH (/)
Penting! Perhatikan slash di akhir path:
# SALAH: Isi direktori 'source' akan disalin ke DALAM 'dest' rsync -av /source /dest/ # Hasil: /dest/source/file1, /dest/source/file2 # BENAR: Isi 'source' disalin ke 'dest' rsync -av /source/ /dest/ # Hasil: /dest/file1, /dest/file2
TROUBLESHOOTING OPTIONS
Debug Connection Issues
# Verbose level 2 rsync -avvv /source/ user@host:/dest/ # Test connection tanpa transfer rsync --list-only user@host:/path/
Handle Permission Issues
# Preserve ownership (butuh root) sudo rsync -avog /source/ /dest/ # Tanpa preserve owner (untuk user biasa) rsync -av --no-o --no-g /source/ /dest/
KOMPARASI OPTIONS POPULER
| Option | Deskripsi | Contoh |
|---|---|---|
-a | Archive mode (preserve all) | rsync -a src/ dest/ |
-v | Verbose output | rsync -av src/ dest/ |
-z | Compression | rsync -az src/ user@host:dest/ |
--delete | Delete extra files | rsync -av --delete src/ dest/ |
--exclude | Exclude pattern | rsync -av --exclude='*.tmp' src/ dest/ |
--progress | Show progress | rsync -av --progress src/ dest/ |
--dry-run | Simulation mode | rsync -av --dry-run src/ dest/ |
Rsync adalah tool yang sangat powerful untuk backup, sync, dan deployment. Pahami options yang sesuai dengan kebutuhan spesifik Anda!
Komentar
Posting Komentar