I'm using rsync
to keep two drives in sync. I use the --archive
flag which is meant to maintain permissions. However, files which are "locked" in Finder do not show as locked after the rsync
operation is complete. How can I replicate the Finder lock during rsync
?
1 Answer
The version of rsync
that macOS provides is about 15-years old and doesn't handle preserving file flags supported by chflags
(e.g. UF_IMMUTABLE
or "Locked" as set with chflags uchg
).
Current versions of rsync have:
--fileflags This option causes rsync to update the file-flags to be the same as the source files and directories (if your OS supports the chflags(2) system call).
Install Homebrew and update rsync
to a modern version with:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew install rsync
If you are doing a remote transfer, both the sending and receiving hosts must support --fileflags
, obviously.
However, if the necessary version of rsync
is not in the default
remote-shell's PATH (i.e. /usr/bin:/bin:/usr/sbin:/sbin
), the path to the requisite version must be specified. This is done with the --rsync-path=PROGRAM
option.
For example:
rsync --fileflags -avz ${HOME}/ remotehost:${HOME}
errors when the remote host's default rsync
doesn't support --fileflags
:
rsync: on remote machine: --fileflags: unknown option
rsync error: syntax or usage error (code 1) at /AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/rsync/rsync-54.120.1/rsync/main.c(1337) [server=2.6.9]
rsync: connection unexpectedly closed (0 bytes received so far) [sender] rsync error: error in rsync protocol data stream (code 12) at io.c(228) [sender=3.2.3]
Assuming the requisite rsync
is installed in /usr/local/bin
, this is resolved with:
rsync --rsync-path=/usr/local/bin/rsync --fileflags -avz ${HOME}/ remotehost:${HOME}