2

I'm looking to control the file mode bits of the directory-to-be-created in the rsync command below:

rsync -a ... <remote-user>@<remote-host>:/some/existing/path/directory-to-be-created/

As the name hopefully implies, that directory does not yet exist and rsync is expected to create it; which it dutifully does... However, near as I can tell it always does this adhering to the <remote-host>'s default umask and no --chmod=... incantation that I can fathom will make it do something else...

So is it possible at all to set the file mode with which a missing target directory will be created, and if so how?

1

rsync may not support that functionality natively, but you could use file systems ACLs to ensure any newly created directory underneath /some/existing/path/ has a specific set of permissions. For example:

$ setfacl -dm u::rwx,g::rx,o::r /some/existing/path/

Newly created directories underneath /some/existing/path/ should now have the permissions 750, manually or through rsync.

  • Interesting... I didn't know about ACLs yet. However, like expecting the system default umask to be, say, 0022, this solution too depends on pre-made provisions at the receiving end... which - as was my experience, and direct cause for this question - can change... I was hoping for a least-assumptions type of solution. – cueedee Nov 4 '19 at 14:33
  • Right, not optimal, but useful for routine rsync operations to similar directory structures (something like backups). – mehlj Nov 4 '19 at 14:35
1

This answer set me on track of the --rsync-path=PROGRAM option:

--rsync-path=PROGRAM

Use this to specify what program is to be run on the remote machine to start-up rsync. Often used when rsync is not in the default remote-shell’s path (e.g. --rsync-path=/usr/local/bin/rsync).

Note that PROGRAM is run with the help of a shell, so it can be any program, script, or command sequence you’d care to run, so long as it does not corrupt the standard-in & standard-out that rsync is using to communicate.

One tricky example is to set a different default directory on the remote machine for use with the --relative option. For instance:

rsync -avR --rsync-path="cd /a/b && rsync" host:c/d /e/

So it would appear that I can just do:

rsync -a --rsync-path='umask 0022 && rsync' ...

... to pre-set the umask (or in fact, any required conditions) before the remote rsync gets invoked :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.