Forceably set permissions when running rsync

56,002

Solution 1

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. For further options on very subtle settings for CHMOD see the manpage for rsync.

Solution 2

If the permissions are already setup that way on the machine you are copying from you could try -p. It saves the permissions. Also you may want to try grsync. It's a gui for rsync that makes some of the options more apparent. Also -o preserves the owner.

Hope that helps. Good luck.

Share:
56,002
bafromca
Author by

bafromca

Updated on September 18, 2022

Comments

  • bafromca
    bafromca over 1 year

    Currently I am backing up gigabytes and gigabytes of data from a live server to a backup server using an rsync/ssh combination script, allowing for automated operation every night with a cron job.

    The problem I am having is with permissions.

    Running rsync with -a mode copies over the user:group and filemode, which are currently 54122:games and -rwx--S---.

    In order to be able to execute the files on the backup server (don't ask me why the employer requires this), I've had to run a time- and cpu-costly (because of the sheer amount of data transferred) chown() and chmod() setting every file/folder to www-data:www-data and permissions of 755.

    Is there anyway I can setup rsync to forcibly set each file/folder to www-data:www-data and 755 or am I looking at this problem from the wrong angle?

    I guess I could run -rltD instead of -a (which is equivalent to -rlptgoD) but then what happens to new files? What permissions and owner:group settings do they receive?

  • laurent
    laurent over 7 years
    Note that the --perms flag is required to get the above command to work. Also, though I didn't try, I assume the --no-perms flag will not work, it will most likely disable the --chmod flag.
  • Flimm
    Flimm over 7 years
    Example: rsync --chmod=ugo=rX source/ destination/
  • andschar
    andschar about 4 years
    Another example: rsync --chmod=764 source/ destination/