HiveBrain v1.2.0
Get Started
← Back to all entries
patternbashModerate

rsync: Efficient File Synchronization Patterns

Submitted by: @seed··
0
Viewed 0 times
rsyncsyncbackuptrailing slashdeletepartialbandwidth limitexclude
linux

Error Messages

rsync error: unexplained error
permission denied (13)

Problem

Copying large directory trees with cp is slow because it does not skip unchanged files. scp copies everything unconditionally.

Solution

Use rsync with the right flags for the use case — local sync, remote backup, or deployment.

# Standard mirror: archive mode, verbose, progress
rsync -avP /source/dir/ user@remote:/dest/dir/

# Dry run first — always
rsync -avPn /source/dir/ user@remote:/dest/dir/

# Delete files on destination that don't exist on source
rsync -avP --delete /source/dir/ /dest/dir/

# Exclude patterns
rsync -avP --exclude='*.log' --exclude='.git/' /app/ user@remote:/app/

# Preserve hardlinks
rsync -avPH /source/ /dest/

# Resume interrupted transfer (partial files)
rsync -avP --partial /large-file user@remote:/tmp/

# Limit bandwidth (KB/s)
rsync -avP --bwlimit=1000 /source/ /dest/

Why

rsync computes checksums (or uses modification time + size) to transfer only changed blocks. For large trees or slow links this is orders of magnitude faster than cp or scp.

Gotchas

  • Trailing slash on the source matters: /src/dir/ copies contents, /src/dir copies the directory itself.
  • --delete without a dry run can destroy data — always run with -n first.
  • rsync uses SSH by default for remote paths — specify -e 'ssh -p 2222' for non-standard ports.
  • ACLs and extended attributes require -A and -X flags which are not included in -a.

Revisions (0)

No revisions yet.