Referência rápida

Rsync: Sincronização de arquivos e backup Guia

Guia rápido de referência para Rsync: transferências incrementais, sincronização remota via SSH, espelhamento de diretórios e exclusões.

· Publicado

Trailing Slash Convention

[!IMPORTANT] Trailing Slash Matters:

  • src (without trailing slash): copies the directory itself (dest/src/files).
  • src/ (with trailing slash): copies only the contents inside src (dest/files).
# Sync contents of src directory into dest
rsync -avz ./src/ /var/backup/

Common Flag Combinations

# Standard archive sync with progress (-a: archive, -v: verbose, -z: compress, -h: human-readable)
rsync -avzh source/ [email protected]:/target/

# Mirror directory (deletes files in target that no longer exist in source)
rsync -avzh --delete source/ target/

# Dry run: preview changes without writing files
rsync -avzh --dry-run source/ target/

Exclusions & SSH Port

# Exclude git directories and node_modules
rsync -avz --exclude '.git' --exclude 'node_modules' ./src/ user@server:/app/

# Use non-standard SSH port (e.g. port 2222)
rsync -avz -e 'ssh -p 2222' ./dist/ user@remote:/www/

Bandwidth Limiting

# Limit transfer bandwidth to 5000 KB/s
rsync -avz --bwlimit=5000 large_dataset.tar remote:/backups/

References

Temas relacionados