Опции для --include
и --exclude
применяются слева направо. Первые варианты всегда самые сильные, поэтому вы можете закончить список --exclude='*/'
, чтобы остановить дальнейшую обработку каталогов.
Однако, как только вы используете --exclude='*/'
, вы отключите неявную обработку всех файлов и каталогов, и вам нужно будет явно указать, какие файлы и папки включать.
A
, B
и E
в все их файлы и папки , D
и его файлы, но не каталоги, D/D2
, D/D4
, /D/D8
и все их файлы и папки , Таким образом, мы можем построить операторы include/exclude следующим образом
rsync --dry-run -av --delete
--include '/A' --include '/A/**'
--include '/B' --include '/B/**'
--include '/E' --include '/E/**'
--include '/D'
--include '/D/D2' --include '/D/D2/**'
--include '/D/D4' --include '/D/D4/**'
--include '/D/D8' --include '/D/D8/**'
-exclude '*/'
src/ dst/
Поскольку вы используете bash
, оболочку, которая может обрабатывать массивы, вы можете безопасно создать набор инструкций --include
. Вот пример:
# It's an array
includes=()
# Start with the fixed set of known directories
for known in A B E
do
includes+=('--include' "/$known" '--include' "/$known/**")
done
# Special case
includes+=('--include' '/D')
# Now the changeable set of subdirectories. You might get this list elsewhere
for subdirs in D2 D4 D8
do
includes+=('--include' "/D/$subdir" '--include' "/D/$subdir/**")
done
# Put it all together
rsync --dry-run -av "${includes[@]}" --exclude '*/' src/ dst/
I can of course create additional directory inside /srv/%u (/srv/sftpuser) owned by sftpuser but is this the only solution with chroot?
# man sshd_config | col -b | sed -n '/^ *ChrootDirectory/,/^ *$/{/^ *$/q;p}' | \
fmt -w72 | sed 's/^/ /'
ChrootDirectory
Specifies the pathname of a directory to chroot(2)
to after authentication. At session startup sshd(8)
checks that all components of the pathname are root-owned
directories which are not writable by any other user
or group. After the chroot, sshd(8) changes the working
directory to the user's home directory. Arguments to
ChrootDirectory accept the tokens described in the
TOKENS section.
Уточним,-все компоненты пути принадлежат root -! Таким образом, вы просто можете сделать:
# man sftp-server | col -b | sed -n '/^ *\-d/,/^ *$/{/^ *$/q;p}' | \
fmt -w72 | sed 's/^/ /'
-d start_directory
specifies an alternate starting directory for users.
The pathname may contain the following tokens that
are expanded at runtime: %% is replaced by a literal
'%', %d is replaced by the home directory of the user
being authenticated, and %u is replaced by the username
of that user. The default is to use the user's home
directory. This option is useful in conjunction with
the sshd_config(5) ChrootDirectory option.