Langsung ke konten utama

Apa itu Rsync?

 

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

bash
rsync [OPTIONS] SUMBER TUJUAN

OPTIONS PALING UMUM

1. Basic Options

bash
# 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

bash
# 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

bash
# 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

bash
# 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

bash
# 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

bash
# 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

bash
rsync -avz --delete --progress \
  /var/www/html/ user@backup-server:/backups/www/

2. Sync Database Backups

bash
rsync -av --partial --progress \
  /backups/db/ user@remote-server:/remote-backups/db/

3. Mirror Directory dengan Exclude

bash
rsync -av --delete --exclude='.git' \
  --exclude='node_modules' --exclude='*.log' \
  /project/ user@production:/opt/project/

4. Transfer dengan Bandwidth Limit

bash
rsync -avz --bwlimit=500 --progress \
  /large-files/ user@remote:/storage/

5. Resume Transfer Besar

bash
rsync -av --partial --progress --append \
  /large-file.iso user@remote:/downloads/

PERBEDAAN TRAILING SLASH (/)

Penting! Perhatikan slash di akhir path:

bash
# 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

bash
# Verbose level 2
rsync -avvv /source/ user@host:/dest/

# Test connection tanpa transfer
rsync --list-only user@host:/path/

Handle Permission Issues

bash
# 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

OptionDeskripsiContoh
-aArchive mode (preserve all)rsync -a src/ dest/
-vVerbose outputrsync -av src/ dest/
-zCompressionrsync -az src/ user@host:dest/
--deleteDelete extra filesrsync -av --delete src/ dest/
--excludeExclude patternrsync -av --exclude='*.tmp' src/ dest/
--progressShow progressrsync -av --progress src/ dest/
--dry-runSimulation modersync -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

Postingan populer dari blog ini

install dan run virtualbox di ubuntu server

  Berikut adalah beberapa cara untuk menginstall VirtualBox di Ubuntu Server: Metode 1: Install dari Repository Official (Rekomendasi) Langkah 1: Tambahkan Repository VirtualBox bash # Update sistem sudo apt update && sudo apt upgrade -y # Install dependencies sudo apt install -y wget curl gnupg apt-transport-https # Tambahkan key repository VirtualBox wget -O- https://www.virtualbox.org/download/oracle_vbox_2016.asc | sudo gpg --dearmor --yes --output /usr/share/keyrings/oracle-virtualbox-2016.gpg # Alternatif jika perintah di atas gagal: wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add - Langkah 2: Tambahkan repository ke sources list bash # Untuk Ubuntu 22.04/Jammy atau versi terbaru echo "deb [arch=amd64 signed-by=/usr/share/keyrings/oracle-virtualbox-2016.gpg] https://download.virtualbox.org/virtualbox/debian jammy contrib" | sudo tee /etc/apt/sources.list.d/virtualbox.list # Sesuaikan de...

Cara Menggunakan sshpass dengan Rsync

  Cara Menggunakan sshpass dengan Rsync Apa itu sshpass? sshpass adalah tool untuk menyediakan password SSH secara non-interactive (tanpa prompt). Sangat berguna untuk automation script. INSTALASI SSHPass Linux (Debian/Ubuntu) bash sudo apt-get install sshpass Linux (CentOS/RHEL) bash sudo yum install sshpass macOS bash brew install hudochenkov/sshpass/sshpass # atau port install sshpass METODE PENGGUNAAN SSHPass DENGAN Rsync 1. Method 1: Environment Variable bash export SSHPASS = "password123" sshpass -e rsync -avz /local/path/ user@103.115.31.218:/remote/path/ 2. Method 2: Password dari File bash # Simpan password di file echo "password123" > /tmp/mypass # Gunakan dengan rsync sshpass -f /tmp/mypass rsync -avz /local/path/ user@103.115.31.218:/remote/path/ # Hapus file password setelah digunakan rm /tmp/mypass 3. Method 3: Password Langsung (TIDAK DISARANKAN) bash sshpass -p "password123" rsync -avz /local/path/ user@103...