5

I'm using rsync to copy some source code. The copied code must not be modified at the destination place by my mistake while code editing. So I set --chmod=u-w flag to make it read-only after copying.

 rsync --delete -a --chmod=u-w

First is working well. But from second time rsync cannot perform copying because destination is read-only.

rsync: delete_file: unlink "/path/file1" failed: Permission denied (13)
rsync: delete_file: unlink "/path/file2" failed: Permission denied (13)
rsync error: some files could not be transferred (code 23) at /SourceCache/rsync/rsync-42/rsync/main.c(992) [sender=2.6.9]

I believe there's some feature that forces rsync to overwrite any files regardless of readonly or writable.

How can I do that?

Eonil
  • 4,657

1 Answers1

5

The copied code must not be modified at the destination place

Wrong: the copied files must be modified at the destination place, when rsync next runs. Unix permissions have no way of expressing “must be modified only by rsync”, unless you run that rsync job as a dedicated user.

Rsync can't delete the files because the directories that contain them are read-only. To avoid this, add the F prefix to apply --chmod only to regular files.

rsync --delete -a --chmod=Fa-w

You might well be better served by not changing the file permissions. If you need to provide read-only access to the files, run the rsync job as a dedicated user, and give other users only read permission to that directory tree (--chmod=go-w might help). Alternatively, expose the directory tree in a read-only view, for example with bindfs (see this answer for a usage example in a different scenario).