Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rsync: how to keep a selected target directory permissions?

What I couldn't figure out is how to sync local files to remote host, while leaving remote folder permissions for a particular folder /var/www/site1/home/images intact, which is 750, while source folder permissions are 770. I need this folder apache-writable locally, but it shouldn't be writable on production server. And I need to keep target permissons only for this folder, for all other files and folders perms must be updated.

Thus far I was experimenting with --exclude, -filter but didn't get the desired effect.

rsync -av --delete /var/www/site1/ [email protected]:/var/www/site1/
like image 239
Evgeny Tryastsin Avatar asked Nov 28 '11 01:11

Evgeny Tryastsin


People also ask

How to change rsync permissions?

Amongst many other options rsync can change permission by running it with the option: rsync [options] --chmod=CHMOD source destination where you can also combine option --archive with the option --no-owner or --no-perms to exclude preservation of owner resp. permissions.

Does rsync create directories automatically if target folders don't exist?

The answer is wrong, rsync won't create directories automatically if target folders don't exist. Sigh. I strongly suggest readers to check the manpage for --relative. It might not do what you think. --relative sticks the full path, rather than the file, at the endpoint you provide on the server.

How to use rsync to sync content between two directories?

Rsync directory with the “-r” option: For direct syncing, utilize the recursive “-r” option in the rsync command. The below-given syntax will sync the content from the source to its destination directory. The “/” points towards the content of the source directory.

What does -O --owner do in rsync?

-o, --owner This option causes rsync to set the owner of the destination file to be the same as the source file, but only if the receiving rsync is being run as the super-user (see also the --super and --fake-super options).


1 Answers

From the rsync man page: -a archive mode; same as -rlptgoD.

-p is preserve permissions, so this should do what you want: -vrltgoD

like image 82
steveax Avatar answered Oct 25 '22 03:10

steveax