Você pode usar um /
inicial para corresponder apenas à raiz da transferência. Tente isto:
rsync -avCz --delete-before --progress --exclude=/test/ /tmp/codebase/ .
Aqui está o snippet da página de manual para o líder /
:
if the pattern starts with a / then it is anchored to a particular spot in the hierarchy of files, otherwise it is matched against the end of the pathname. This is similar to a leading ^ in regular expressions. Thus "/foo" would match a name of "foo" at either the "root of the transfer" (for a global rule) or in the merge-file’s directory (for a per-directory rule). An unqualified "foo" would match a name of "foo" anywhere in the tree because the algorithm is applied recursively from the top down; it behaves as if each path component gets a turn at being the end of the filename. Even the unanchored "sub/foo" would match at any point in the hierarchy where a "foo" was found within a directory named "sub".
E para o trailing /
:
if the pattern ends with a / then it will only match a directory, not a regular file, symlink, or device.
Atualizar
Acredito em seus comentários que você também está procurando a opção --delete-excluded
.