3

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?

wellwellwell
  • 63
  • 1
  • 8

1 Answers1

4

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/'{}' \;
HBruijn
  • 77,029
  • 24
  • 135
  • 201
  • 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 '19 at 19:48