#StackBounty: #linux #permissions #rsync Set permissions with rsync for all files but the root directory

Bounty: 50

I want to sync two directories with rsync, preserving the permissions of all files. My user foo does have write access to the target directory, but does not own it.

$ ls -l                                                                                                                                                                                
total 8
drwxrwx--- 2 foo  foo 4096 Jun  3 16:01 a
drwxrwxr-x 3 root foo 4096 Jun  3 16:02 b

While syncing does work, it causes a permission error and a bad exit code:

$ rsync -av  -O  --delete a/ b/                                                                                                                                                        
sending incremental file list
rsync: failed to set permissions on "/tmp/r/b/.": Operation not permitted (1)
deleting 2
./
1

sent 115 bytes  received 138 bytes  506.00 bytes/sec
total size is 0  speedup is 0.00
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1196) [sender=3.1.2]

I am aware, that I could use the --no-perm option, but this would prevent setting the permissions of any files and not just of the target directory.

Another solution would be to use rsync -av --delete a/* b/, but this would prevent deleted files in a/ from being removed in b/.

This is probably a duplicate of this question, which remains unanswered since 2010 🙁


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.