Skip to content
Latchkey

rsync Command Reference for CI Scripts

rsync copies only the differences, making repeat transfers fast.

rsync is the workhorse for deploys and cache restores. The two things that bite people are the trailing-slash semantics on the source path and the destructive --delete flag.

Common flags/usage

  • -a / --archive: recurse and preserve perms, times, and symlinks
  • -z: compress during transfer
  • --delete: remove dest files not in source (mirror)
  • --exclude=PATTERN: skip matching paths
  • -n / --dry-run: show what would change without doing it

Example

shell
rsync -avz --delete --exclude='.git' \
  -e "ssh -i ${HOME}/.ssh/id_ed25519 -o BatchMode=yes" \
  ./dist/ "deploy@${HOST}:/var/www/app/"

In CI

A trailing slash on the source (dist/) copies its contents; without it (dist) the directory itself nests under the dest, a frequent "wrong layout" bug. Always --dry-run before using --delete. Exit 23 means a partial transfer (some files vanished or were unreadable); exit 12 usually means an SSH/auth failure on the remote.

Key takeaways

  • A trailing slash on the source copies contents; omitting it nests the directory.
  • --delete mirrors and is destructive, so --dry-run first.
  • Exit 23 is a partial transfer; exit 12 is usually a remote SSH failure.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →