Page 1 of 1

inherit and keep permission destination with rsync

Posted: 2020/06/05 04:37:50
by cuongtl
Hi all,
I want to sync from source-folder /data to destination-folder /backup with condition: all files and subfolder after sync will inherit permission from folder /backup.
Anyone can show me a method?

Re: inherit and keep permission destination with rsync

Posted: 2020/06/05 06:42:40
by Jean-Pierre
This is probably possible through the use of Posix ACLS :

- mount /backup with option acl
- define the base for inheritance on /backup :

Code: Select all

[linux@optiplex ~]$ sudo mount -o remount,acl /home
[linux@optiplex ~]$ mkdir backup
[linux@optiplex ~]$ setfacl -m 'd:u::rw,d:g::w,d:o::r,d:m::rwx' backup
[linux@optiplex ~]$ getfacl backup
# file: backup
# owner: linux
# group: linux
user::rwx
group::r-x
other::r-x
default:user::rw-
default:group::-w-
default:mask::rwx
default:other::r--
- check

Code: Select all

[linux@optiplex ~]$ cd backup
[linux@optiplex backup]$ umask
0022
[linux@optiplex backup]$ touch file
[linux@optiplex backup]$ ls -l file
-rw-rw-r--+ 1 linux linux 0 Jun  5 08:33 file
[linux@optiplex backup]$ getfacl file
# file: file
# owner: linux
# group: linux
user::rw-
group::-w-
mask::rw-
other::r--
Notes : when acls are in use, the second set of rwx shown by ls is the mask, not the group permissions. Also the umask is ignored, and inheritance does not apply to ownership.

In your situation, you have to make sure the inherited permissions are not overwritten by rsync.