SkillPilotAI

rsync (2/2)

Part 2 of rsync covers argument handling, compression, filter rules, partial transfers, logging and itemize codes, the rsync daemon (server and client), batch mode, environment variables and exit codes. These are what make rsync safe and scriptable in production.

147.1 Two ways in: ssh vs daemon

Remote shell mode (ssh)
  1. 1.Client logs in with ssh on port 22

  2. 2.ssh starts remote rsync with --server --sender (internal options)

  3. 3.Both rsync processes exchange the file list inside the ssh tunnel

  4. 4.Only changed data travels, encrypted by ssh

Daemon mode (rsync:// port 873)
  1. 1.Client connects directly to rsyncd on TCP 873 (host::module or rsync://)

  2. 2.Daemon sends the module list (pub, backup, admin)

  3. 3.For an auth module the daemon sends a password challenge

  4. 4.Client replies with an MD5 response

  5. 5.Correct: transfer starts; wrong: auth failed (exit 5)

Daemon data is plain TCP, not encrypted

147.2 Argument handling and security

  • New rsync escapes spaces in remote paths with backslashes by default.
  • --old-args lets the remote shell split the path into words: exit 23.
  • -s / --secluded-args (old name --protect-args) sends filenames inside the protocol, never on the remote command line.
  • --trust-sender skips extra client checks of the sender's file list: only for trusted hosts.
Terminal
rsync -av -e showrsh 'b:/srv/my docs/a simple file.txt' d/rsync -av --old-args -e showrsh 'b:/srv/my docs/a simple file.txt' d/   # exit 23rsync -av -s -e showrsh 'b:/srv/my docs/a simple file.txt' d/rsync -av --protect-args -e showrsh 'b:/srv/my docs/a simple file.txt' d/
Output
$ rsync -av --protect-args -e showrsh 'b:/srv/my docs/a simple file.txt' d/REMOTE: b rsync --server --sender -svlogDtpre.iLsfxCIvucreated directory da simple file.txt(exit 0)

147.3 Compression

  • -z compresses data; the new default algorithm is zstd level 3 (5 MB text log -> ~390 KB sent).
  • --zc (compress-choice) picks zstd, lz4, zlibx, zlib or none; --zl sets the level (zlib 1-9).
  • -zz is only for old servers; --skip-compress has no effect today.
  • Use -z on slow links, keep it off on a fast LAN.
Terminal
rsync -a --stats zsrc/ b:/tmp/z/          # ~5,000,000 bytes sentrsync -a -z --stats zsrc/ b:/tmp/z/       # zstd level 3rsync -a --zc=lz4 --stats zsrc/ b:/tmp/z/rsync -a --zc=zlib --zl=9 --stats zsrc/ b:/tmp/z/rsync -a -z --stats --skip-compress=gz/jpg/mp[34]/7z/bz2 zsrc/ b:/tmp/z/
Output
$ rsync -a -z --stats --skip-compress=gz/jpg/mp[34]/7z/bz2 zsrc/ b:/tmp/z/Total bytes sent: 392,891

147.4 Filtering: options

  • First matching rule wins: --include='*/' --include='*.c' --exclude='*' copies only .c files.
  • --exclude-from / --include-from read patterns from a file (- = stdin).
  • -F reads .rsync-filter in every folder (-FF also hides the filter files); -C ignores CVS-style junk (.o, .bak, .git...).
  • --files-from sends only listed files (implies -R, -d); --from0 for NUL-separated names.
Terminal
rsync -anv --exclude='*.tmp' --exclude='.git/' proj/ out/rsync -anv --include='*/' --include='*.c' --exclude='*' proj/ out/rsync -anv --exclude-from=ex.txt proj/ out/rsync -anvF proj/ out/       # reads .rsync-filter in every folderrsync -anvC proj/ out/       # CVS-style ignores
Output
$ rsync -anvC proj/ out/main.cnotes.tmpdocs/guide.mdlib/util.c

147.5 Filter rule types and patterns

Rule / patternMeaning
- / +Exclude / include
. / :Merge a rules file / dir-merge a file in every folder
H / SHide / show on the sender only
P / RProtect / risk on the receiver (affects --delete)
!Clear the rule list so far
* / ** / ?Non-slash chars / across slashes / one char
/foo, foo/, dir/***Anchor at transfer root / dirs only / dir and everything inside
Terminal
rsync -anv -f'- *.o' -f'- .git/' proj/ out/rsync -anv -f'+ */' -f'+ *.c' -f'- *' proj/ out/rsync -anv -f'S keep.bak' -f'H *.bak' -f'- .git/' proj/ out/rsync -anv -f'. rules.txt' -f'- .git/' proj/ out/rsync -anv -f': .rules' -f'- .git/' proj/ out/rsync -anv -f'- *.bak' -f'!' -f'- *.tmp' -f'- .git/' proj/ out/
Output
$ rsync -anv -f'- *.bak' -f'!' -f'- *.tmp' -f'- .git/' proj/ out/keep.bakmain.cmain.oold.baklib/util.o

Receiver side: P protects matching files even from --delete; R removes that protection:

Terminal
rsync -anv --delete -f'P *.log' -f'- old/' proj/ dst/rsync -anv --delete -f'R old.log' -f'P *.log' -f'- old/' proj/ dst/
Output
$ rsync -anv --delete -f'R old.log' -f'P *.log' -f'- old/' proj/ dst/deleting logs/old.logcannot delete non-empty directory: logsdeleting stale.txtdeleting my.local

147.6 Rule modifiers

  • / matches the absolute path; ! inverts the rule; C inserts CVS rules.
  • s applies only on the sender, r only on the receiver (my.local survived --delete).
  • p (perishable) lets --delete clean a folder holding only excluded files.
  • e excludes the merge file itself; x applies the rule to xattrs; n stops inheritance into subfolders; + / - say the merge file has only includes / excludes.
Terminal
rsync -anv -f'-/ /lab/proj/main.c' proj/ out/   # absolute pathrsync -anv -f'-! */' proj/ out/                 # invertedrsync -anv -f'-s *.bak' -f'- .git/' proj/ out/  # sender onlyrsync -anv --delete -f'-r *.local' proj/ dst/   # receiver onlyrsync -anv --delete -f'-p *.o' proj/ dst/       # perishablersync -aX -f'-x user.secret' proj/main.c xo/    # xattr rule
Output
$ getfattr -d proj/main.c# file: proj/main.cuser.owner="dev"user.secret="lab"$ rsync -aX -f'-x user.secret' proj/main.c xo/$ getfattr -d xo/main.c# file: xo/main.cuser.owner="dev"

147.7 Partial transfers, progress and logging

  • Interrupted transfer gave exit 20; --partial-dir kept the unfinished file; -P (= --partial --progress) resumed with matched data.
  • --progress prints per file; --info=progress2 one line for the whole transfer.
  • --out-format='%t %i %n%L' custom line per file; --log-file writes details with PID; -M--log-file logs on the remote side.
  • -h / -hh / --no-h: units of 1000 / 1024 / plain digits; --list-only (or no DEST) lists instead of copying.
Terminal
timeout 2 rsync -a --bwlimit=500 \  --partial-dir=.rsync-partial big.iso b:/tmp/p/      # exit 20rsync -aP --partial-dir=.rsync-partial --stats big.iso b:/tmp/p/rsync -a --progress zsrc/ b:/tmp/pq/rsync -a --info=progress2 zsrc/ b:/tmp/pp/
Output
$ rsync -a --info=progress2 zsrc/ b:/tmp/pp/      4,688,895  93%    4.74MB/s    0:00:00 (xfr#1, to-chk=1/3)      4,988,963 100%    4.46MB/s    0:00:01 (xfr#2, to-chk=0/3)
Terminal
rsync -a --out-format='%t %i %n%L' it/ /tmp/of/rsync -a --log-file=/tmp/r.log it/ /tmp/lf/rsync -a --stats -h zsrc/ /tmp/s1/rsync --list-only it/
Output
$ rsync --list-only it/drwxr-xr-x          4,096 2026/11/09 05:20:18 .-rw-r--r--             21 2026/11/09 05:20:08 index.html-rw-r--r--              2 2026/11/09 05:20:18 new.txtdrwxr-xr-x          4,096 2026/11/09 05:20:08 css

147.8 Itemize-changes codes (YXcstpoguax)

PositionValues
Y (update type)< sent, > received, c local change, h hard link, . no update, * message (deleting)
X (file type)f file, d dir, L symlink, D device, S special
c s tchecksum differs, size differs, time differs
p o gpermissions, owner, group
u a xatime/crtime, ACL, xattr
. + ?same, new item, unknown
Terminal
rsync -ai it/ itd/# index.html changed, old.txt removed, css touchedrsync -ai --delete it/ itd/chmod 600 it/css/site.cssrsync -ai it/ itd/
Output
$ rsync -ai --delete it/ itd/*deleting   old.txt.d..t...... ./>f.st...... index.html$ chmod 600 it/css/site.css$ rsync -ai it/ itd/.f...p..... css/site.css

147.9 Daemon mode (server)

  • rsyncd.conf: each [module] is a named folder; global hosts allow limits clients to the lab subnet.
  • pub is read only; backup has auth users + a secrets file readable only by root (-rw-------); admin allows only one other IP.
  • rsync --daemon listens on 873; --port/--address start a second daemon; -M overrides a conf setting; --no-detach for foreground; --bwlimit caps the daemon.
  • The daemon log shows every connect, module request, auth failure and denied access.
Output
uid = nobodyuse chroot = yeslog file = /var/log/rsyncd.loghosts allow = 192.168.167.0/24[pub]  path = /srv/pub  read only = yes[backup]  path = /srv/backup  read only = no  auth users = backup  secrets file = /etc/rsyncd.secrets[admin]  hosts allow = 192.168.167.99
Terminal
rsync --daemonnetstat -ltn | grep ':873 'rsync --daemon --port=8730 --address=192.168.167.20 \  --log-file=/var/log/rsyncd-8730.log \  -M 'pid file=/run/r8730.pid'cat /var/log/rsyncd.log
Output
$ cat /var/log/rsyncd.log2026/11/09 05:20:59 [188] rsyncd version 3.4.3 starting, listening on port 8732026/11/09 05:21:03 [192] module-list request from a (192.168.167.10)2026/11/09 05:21:06 [193] rsync on pub/ from a (192.168.167.10)2026/11/09 05:21:16 [196] auth failed on module backup from a (192.168.167.10) for backup: password mismatch2026/11/09 05:21:34 [204] rsync denied on module admin from a (192.168.167.10)

147.10 Daemon access (client side)

  • rsync rsync://host/ lists modules; host::module with no destination lists files.
  • Password via RSYNC_PASSWORD or --password-file (must be chmod 600, a world-readable file is refused).
  • Pushing to a read-only module errors; hosts allow denies the admin module (exit 5).
Terminal
rsync rsync://192.168.167.20/                 # module listrsync -av rsync://192.168.167.20/pub/ /tmp/pub/rsync b::pub                                  # list filesRSYNC_PASSWORD=LAB-ONLY-placeholder-147 \  rsync -ai it/ rsync://backup@192.168.167.20/backup/chmod 600 /root/rsync.passrsync -ai --password-file=/root/rsync.pass it/ backup@b::backup/rsync rsync://192.168.167.20/admin/
Output
$ RSYNC_PASSWORD=LAB-ONLY-placeholder-147 rsync -ai it/ rsync://backup@192.168.167.20/backup/.d..t...... ./<f+++++++++ index.html<f+++++++++ new.txt<f+++++++++ css/site.css(exit 0)$ rsync rsync://192.168.167.20/admin/@ERROR: access denied to admin from a (192.168.167.10)rsync error: error starting client-server protocol (code 5) at main.c(1865) [Receiver=3.4.3](exit 5)

147.11 Batch mode and environment variables

  • --write-batch updates one destination and records the changes; --read-batch replays them on another (diff shows identical).
  • --only-write-batch writes just the batch file, destination untouched.
  • RSYNC_RSH = default remote shell; RSYNC_PROTECT_ARGS=1 = -s by default; USER/LOGNAME = daemon username; RSYNC_PASSWORD.
  • Others: RSYNC_PROXY, RSYNC_CONNECT_PROG, RSYNC_PARTIAL_DIR, RSYNC_COMPRESS_LIST, RSYNC_CHECKSUM_LIST, CVSIGNORE.
Terminal
rsync -a --write-batch=/tmp/up it/ b1/rsync -av --read-batch=/tmp/up b2/diff -r b1 b2 && echo b1 == b2rsync -a --only-write-batch=/tmp/up2 it/ b3/RSYNC_RSH=showrsh RSYNC_PROTECT_ARGS=1 rsync -a 'b:/srv/my docs/' md/

147.12 Exit codes

CodeMeaning
0Success
1Syntax or usage error
5Error starting client-server protocol (e.g. daemon auth/access denied)
10Socket I/O error (connection refused)
12Protocol data stream error (e.g. no rsync on remote)
20Interrupted (SIGINT/SIGUSR1)
23Partial transfer due to error (missing source)
24Partial transfer: source files vanished
25--max-delete limit stopped deletions
30 / 35Send/receive timeout / daemon connection timeout
Terminal
rsync -a nothere.txt /tmp/x/; echo $?                   # 23rsync -a --rsync-path=/no/such/rsync it/ b:/tmp/x/      # 12rsync rsync://192.168.167.20:9999/; echo $?
Output
$ rsync rsync://192.168.167.20:9999/; echo $?rsync: [Receiver] failed to connect to 192.168.167.20 (192.168.167.20): Connection refused (111)rsync error: error in socket IO (code 10) at clientserver.c(141) [Receiver=3.4.3]10

--server and --sender are internal options rsync builds for the remote side; never type them by hand (only forced-command setups like rrsync check them).

147.13 Comparison: rsync over ssh vs rsync daemon

Pointrsync over sshrsync daemon
Port22 (ssh)873
UsersSystem users via sshauth users + secrets file
EncryptionYes (ssh)No, plain TCP
Access controlssh keys, sshd configModules, hosts allow, read only

147.14 Common mistakes

  • Thinking a daemon password encrypts data: only auth is challenge-response, data is plain on 873; use a VPN or ssh tunnel.
  • Treating exit 24 as failure in backup scripts: vanished live logs are normal; treat 0 and 24 as OK, alert on 23.
  • Wrong rule order: the first matching filter rule wins.
  • World-readable password file: rsync refuses it.
  • Using -z on a fast LAN: wastes CPU.

147.15 Interview tips

  • ssh mode: login via ssh, remote rsync --server, encrypted. Daemon mode: port 873, modules, auth users, hosts allow, unencrypted.
  • Exit 23 / 24 mean a partial transfer; 24 = files vanished (normal for live logs).
  • Filters: first match wins; P/R protect or risk files on the receiver during --delete.
  • -i itemize codes like >f.st...... tell exactly what changed and why.