1

I have a source folder

source/

-rw-r--r-- 1 27773 27773 12 Mar 23 21:41 aws-1                                                                                         
-rw-r--r-- 1 27773 27773 12 Mar 23 21:41 aws-2 

the destination folder doesn't exist yet. And I try to rsync the 2 aws files into a destination folder. Here is my command:

rsync \
--include="aws*" \
--exclude="*" \
-avh --chmod=a=rw "source/." "destination"

What I'm trying to do is to rsync the 2 aws files and change their permissions once in the destination folder. After running the command, I got an error and the files are not in the destination folder. Only the folder is created. Here is the error:

sending incremental file list                                                                                                          
created directory destination                                                                                                          
rsync: failed to modify permissions on "/home/cg/root/destination/.": Permission denied (13)                                           
rsync: recv_generator: failed to stat "/home/cg/root/destination/aws-1": Permission denied (13)                                        
rsync: recv_generator: failed to stat "/home/cg/root/destination/aws-2": Permission denied (13)                                        
./                                                                                                                                     

sent 88 bytes  received 346 bytes  868.00 bytes/sec                                                                                    
total size is 24  speedup is 0.06                                                                                                      
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1165) [sender=3.1.1]

It says permission denied without copying the files. I don't already understand which permission cause problem. My source file and directory seems fine. The created destination folder seems also fine.

PS: I precise my rsync command happens inside a bash script

  • why are you adding the . to source/. ? also, if destination exists you need a trailing slash. – bistoco Mar 23 '17 at 22:05
  • Have you tried a sudo? Example, sudo chmod a+r * – Soren Mar 23 '17 at 22:07
  • @bistoco removing the . doesn't change anything and the destination folder doesn't exist yet. @moo_we_all_do after applying chmod to the files in source/ works but I still have the same error with rsync – eakl Mar 23 '17 at 22:16
  • i cannot find any working example for your --chmod=a=rw syntax, the closest is this – bistoco Mar 23 '17 at 22:19
  • I suspect what may be happening is that rsync is successfully removing execute permission from destination - which then prevents it from being accessed to complete the rest of the transfer. Try --chmod=a=rwX instead. – steeldriver Mar 23 '17 at 22:29
0

Directories need execute permission in order for processes to access (open) them.

When you use --chmod=a=rw, the destination directory gets created but then immediately gets its permissions set to drw-rw-rw such that its contents become inaccessible ("failed to stat") e.g. given

$ tree
.
└── source
    ├── file1
    ├── file2
    └── file3

1 directory, 3 files

then

$ rsync --include="file*" --exclude="*" -avh --chmod=a=rw source/ destination/
sending incremental file list
created directory destination
rsync: failed to modify permissions on "/home/steeldriver/destination/.": Permission denied (13)
rsync: recv_generator: failed to stat "/home/steeldriver/destination/file1": Permission denied (13)
rsync: recv_generator: failed to stat "/home/steeldriver/destination/file2": Permission denied (13)
rsync: recv_generator: failed to stat "/home/steeldriver/destination/file3": Permission denied (13)
./

sent 107 bytes  received 502 bytes  1.22K 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(1183) [sender=3.1.1]

fails because

$ ls -dl destination/
drw-rw-rw- 2 steeldriver steeldriver 4096 Mar 23 18:24 destination/

so that

$ ls -al destination/
ls: cannot access 'destination/.': Permission denied
ls: cannot access 'destination/..': Permission denied
total 0
d????????? ? ? ? ?            ? .
d????????? ? ? ? ?            ? ..

The solution is to use --chmod=a=rwX (or, equivalently, --chmod=ugo=rwX)

$ rsync --include="file*" --exclude="*" -avh --chmod=ugo=rwX source/ destination/
sending incremental file list
created directory destination
./
file1
file2
file3

sent 224 bytes  received 110 bytes  668.00 bytes/sec
total size is 0  speedup is 0.00

where the X symbolic mode means

execute/search only if the file is  a  directory  or
already  has  execute permission for some use

See man chmod

  • Thx steeldriver. Very good answer and it solved my problem – eakl Mar 24 '17 at 1:54

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.