Rsync + chmod multiple files

bashpermissionrsync

I have a source folder

source/

-rw-------@ 1 user  staff    41B Mar 23 13:59 aws-1
-rw-r--r--  1 user  staff   112B Mar 23 14:36 aws-2
-rw-rw-rw-@ 1 user  staff   2.3K Feb  5 17:15 google

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 \
  -avh --chmod=a=rw \
  --include="aws-*" \
  --exclude="*" \
  "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:

building file list ... done
created directory /Users/user/destination/aws
./
rsync: recv_generator: failed to stat "/Users/user/destination/aws/aws-1": Permission denied (13)
rsync: recv_generator: failed to stat "/Users/user/destination/aws/aws-2": Permission denied (13)
rsync: recv_generator: mkdir "/Users/user/destination/aws/." failed: Permission denied (13)
*** Skipping everything below this failed directory ***

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

Best Answer

The problem you are having is almost certainly due to rsync attempting to create a directory that already exists.

Given that your source and destination are on the same computer then using rsync is overkill. Instead try

mkdir -p /Users/user/destination/aws ; cp source/aws-* /Users/user/destination/aws

This creates the destination directory if it doesn't exist and then does a copy.