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
scp Command Reference for CI Scriptsscp copies files between hosts over SSH in CI deploys. Reference for -r, -i, and -P, plus the uppercase-port…
ssh Command Reference for CI Scriptsssh opens a secure remote shell or runs a remote command in CI deploys. Reference for -i, -o, BatchMode, and…
tar Command Reference for CI Scriptstar bundles and extracts archives in CI for caches and artifacts. Reference for -c, -x, -z, -C, and the compr…
cp Command Reference for CI Scriptscp copies files and directories in CI for staging artifacts. Reference for -r, -p, -a, and trailing-slash beh…