0

I am using AWS CodeDeploy to copy files from git to the server. It can't overwrite the files, so I have to move the files to another temp location and then it moves the files from the repo to the original server /var/www.

I'd like to keep the permissions for the directories and files the same as before and so can I use rsync to sync only permissions and ownership using the older files in the temp folder to this new folder, but not the files themselves?

0

AFAIK there are no rsync flags to only sync ownership and permissions but both the chmod and chown commands support a --reference flag.

You can point to an existing file and chmod will use the permissions of that file instead of you needing to supply MODE values when changing the file mode.
Similarly chown will use the owner and group of that reference file/directory rather than specifying OWNER:GROUP values.

You can then do something along the lines of:

cd /template/
find . -exec chmod -v --reference='{}' /path/to/target/'{}' \;
find . -exec chown -v --reference='{}' /path/to/target/'{}' \;
  • For the chown command I get a cannot access error when it tries to match with files in target subdirectories, even though the reference and target folders have the same exact trees. – wellwellwell Jun 14 at 19:48

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.